web developer & system programmer

coder . cl

ramblings and thoughts on programming...

how I won my latest project

published: 19-09-2012 / updated: 19-09-2012
posted in: development, programming, projects, python, tips
by Daniel Molina Wegener

As freelancer I am constantly looking for new projects. Sometimes is hard to find good projects, mainly because not all customers are technical customers, making hard to communicate some aspects of the project, among other stuff like programmer evaluation, without too much technical evaluation, mostly based on his accreditations. One of my latest projects was earned by handling a programming problem on the middle of the interview, I was using Skype to share my screen and allow the customer to review the source code and watch me how I was solving the problem. That was great.

I was very glad to see how a technical customer was reviewing my code, making live suggestions about the solution. The problem was not so hard to solve, and was related to parsing algorithms. Given a set of characters on a string, you must find brace pairs, like {}, () and [], distributed on any place of the string but the correctness of the format is given with symmetric pairs. For example “a[a[b(c)]]{d}” is a correct string, and “a[a][b(c){d}” is not. How to parse that kind of strings?, using regular expressions was not an option, so the algorithm is just an O(n) algorithm that uses a stack and a dictionary to review each brace pair. The language of choice was Python, and was great to handle that problem in less than 20 minutes.

#!/usr/bin/env python
# -*- coding: utf-8; -*-

def par_match(str_):
    test_m = {'{': '}', '(': ')', '[': ']'}
    chm = None
    stk = list()
    for ch in str_:
        if ch in test_m:
        if ch in test_m.values() and len(stk) > 0 and ch == stk[-1]:
        if ch in test_m.values() \
           and ((len(stk) > 0 and ch != stk[-1]) or (len(stk) == 0)):
            return False
    return (len(stk) == 0)

if __name__ == "__main__":
    print(par_match("< {<{}>}>"))

The simplicity of the algorithm is very nice. Is pretty clear how the stack is used to hold brace positions and which pair should match the next closing brace. All error conditions are checked at the end, passing to the next character in the string if the matching char is correct and checking that the stack is empty at the end to check if there an opened brace that was not closed. The customer was pleased with the solution and he have hired me. But the interesting fact of getting hired due to the technical interview through Skype was very nice. We were talking about the solution and the perspective to solve the problem. As we were getting known as customer and freelancer.

Is very nice to work with people that understands your perspective on programming and your passion for your work. Even if we are not sharing a personal meeting on a Starbucks or Starlight coffee shop, having a nice time, was nice to meet through Skype, have a coffee made from beans on my moka pot and talk about programming with a customer that takes programming as a serious activity and recognizes that it cannot be handled by anyone. Also he have shared with me that there are some very good technicians, with a deep technical knowledge, but not so good solving programming problems. Seems that my customer have accepted that not everyone have real conditions to program, but having good skills on programming is just a subject of interest and practice, not a mechanical learning on a classroom.

No coments yet.

post a comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>