## Steve Yegge’s Phone-Screen Coding Exercises

### June 30, 2009

Steve Yegge is a programmer and popular blogger. One of his blog entries proposes these seven phone-screen coding exercises:

- Write a function to reverse a string.
- Write a function to compute the Nth fibonacci number.
- Print out the grade-school multiplication table up to 12 x 12.
- Write a function that sums up integers from a text file, one per line.
- Write a function to print the odd numbers from 1 to 99.
- Find the largest int value in an int array.
- Format an RGB value (three 1-byte numbers) as a 6-digit hexadecimal string.

Your task is to write solutions to stevey’s phone-screen exercises. When you are finished, you are welcome to read a suggested solution, or to post your solution or discuss the exercise in the comments below.

Advertisements

[…] Praxis – Steve Yegge’s Phone-Screen Coding Exercises By Remco Niemeijer Today’s Programming Praxis problem is an easy one. In 2005, Steve Yegge posted an article about […]

My Haskell solution (see http://bonsaicode.wordpress.com/2009/06/30/programming-praxis-steve-yegge%E2%80%99s-phone-screen-coding-exercises/ for a version with comments):

C# Solution

I couldn’t resist writing smartass responses for questions three and five to just return fixed strings. I also wrote more general answers that I thought were more in keeping with the spirit of the exercise.

The basic recursive implementation for Fibonacci numbers is a classic, but is terribly slow. It’s the answer I’d expect out of most interview candidates as a first pass since it is taught so regularly as an example of recursion. However, they’d be in trouble if they couldn’t quickly identify the problems with such an implementation. I wrote out a couple of alternatives that are a bit more efficient.

Thanks to nonowarn for catching a bug:

The correct code for exercise 1 should be

I think you’ve got them all, Remco. My Haskell solutions are similar. Here is one simpler solution to #5:

printOdds = print [1,3..99]

There’s one more bug in Remco’s code, though: largest assumes positive integers, but it should read:

largest = foldl1 max

Yeah, I noticed that one too, but didn’t get round to fixing it. However, if you treat Steve Yegge’s solution as the spec then the correct implementation is actually

largest = foldl max minBound

[…] for the exercise, I picked Steve Yegge’s Phone-Screen Coding Exercises, figuring seven different small problems might cover slightly more ground than one bigger […]

I’m never sure how much of a language’s built-in functionality we’re supposed to use for a question.

Python solution

Common Lisp solution

For the RGB => Hex conversion you can always take advantage API knowledge (such as string formatting features), but its not as fun!