Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

This is one test I've used: write a program that reads a text file and then prints out all the lines in reverse order.


I love interview questions that make Python look awesome.


  python -c "print '\n'.join(open('file.txt').readlines()[::-1])"
Hmmm, slightly longer then the Perl version ;-)

  python -c "print '\n'.join(reversed(list(open('test.py'))))"
Somewhat more elegant, but still lots of parentheses.


It's also wrong - "readlines" keeps the "\n", and you've added another one between lines.


Indeed. A cosmetic refinement, but it should really be:

  python -c "print ''.join(reversed(list(open('test.py'))))"
That's even two characters less!


Good, but too easy. Assume you can't keep the file in memory.


   perl -e 'print reverse <>' <file>
;)


Out of curiosity, why do you think questions like reverse a list without using reverse features of the language, or print out a file backwards a good judge of development skills?

I've been programming over 10 years and my opinion is that some of these questions aren't relevant for many development jobs.


Firstly, this is nothing to do about finding a good developer, it's to find out whether someone can program at all. I thought that would be clear from reading this thread, but perhaps it's now long enough that you haven't read it all, even though you have replied to a comment fairly deep in the hierarchy.

Secondly, this question didn't ask not to use the "reverse" features in the language. Indeed, the suggested solutions do use the reverse features.

Thirdly, perhaps this particular task is a good one, perhaps it isn't. Even so, it seems good enough to cull those who can't program at all. The point with these exercises isn't to get it right first time, it's to see if the candidate has a clue at all. If they get it right first time then you have a prospect. Treasure them and move to discuss design, style, ideas, and interesting stuff.

Finally, do you know any actively employed, productive developer who cannot write FizzBuzz in less than 10 minutes?


I don't even know if this is the answer. The reason being I have never needed to work with fractions or with the modulus operator (I'm 12 years out of school, which is the last time I need it). The only reason I know about it is because I was asked about a question involving the modulus character in an interview.

But I can tell you I have had many clients that have been happy with my work.

<code> for (e in 1..100) { if ((e % 3 == 0) && (e % 5 == 0)) { println "FizzBuzz" } else if (e % 3 == 0) { println "Fizz"} else if (e % 5 == 0) { println "Buzz"} else println e } </code>


Bingo.

That's good enough to avoid having your resume deep-sixed. The next stage would depend on the position you're applying for, and whether it's algorithms, web, systems, maintenance, whatever. There are now several questions I could pursue, but that's enough to get you through the door, offered a beverage of your choice, and effectively courted.

By the way, not knowing what the modulus operator is no bar - all you have to do is write:

    if is_divisible_by(n,d) ...
or something similar, and then say - "I'd need to look up the idiomatic way to do that in your language of choice."

But you are already way ahead of the game. FWIW, when we have been hiring (which we aren't now, by the way) the person who wrote something like that got the job. And yes, out of several tens of applications, only one could do it.




Consider applying for YC's Summer 2026 batch! Applications are open till May 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: