It's useful as a very early screening because it eliminates a lot of people who are wasting your time and is so simple as to have almost to false negatives. It has no complexity, no algorithm or concepts you might be unfamiliar with- just the for loop, the conditional, and the modulo operator. No one who claims to be a professional developer should fail it.
Write a program that prints the numbers 1 to 100. However, for multiples of 3 print "Fizz" and for multiples of 5 print "Buzz". For multiples of both 3 and 5, print "FizzBuzz".
I've gotten that one a few times, and I always write something that only contains the string 'Fizz' once and 'Buzz' once (i.e., doesn't say 'FizzBuzz' separately, just uses the same logic to print 'Fizz' and 'Buzz' both), because I figured that was partly the point; otherwise it would be "print 'Zarples' for both multiples". I've been told that it's the first time the interviewer saw it done that way, and now I see several replies here that also would take no modification to use 'Zarples' instead of 'FizzBuzz'.
No point to this, I guess, other than that even something as simplistic as this is open to interpretation.
A couple of suggestions: functions like rem look better infix:
x `rem` 3
this means the same thing but is more readable (I think).
Instead of folding, just map putStrLn over the list:
mapM_ (putStrLn . show') [1..100]
mapM_ is just a version of map for monads that ignores its result (it returns m () instead of m a). You can also use forM_ which is mapM_ with its arguments reversed.
Finally, I think this site lets you format code by putting four spaces in front of each line. I hope :)
Edit: One other thing. You don't need all those parentheses in the first line.
rem x 3 == 0 && rem x 5 == 0 = "FizzBuzz"
x `rem` 3 == 0 && x `rem` 5 == 0 = "FizzBuzz"
Both versions should work and I think they are easier to read. I could see (rem x 3 == 0) also being clear, but the outermost parentheses do not help at all.
A trivial piece of code that a candidate should be able to write as quickly as they can type on a computer or write on the board designed to test that (1) they can write basic code and (2) they've written enough code that trivial problems are trivial. Jeff Atwood coined the phrase [1] and gave the classic example:
Write a program that prints the numbers from 1 to 100. But for multiples
of three print "Fizz" instead of the number and for the multiples of five
print "Buzz". For numbers which are multiples of both three and five print
"FizzBuzz".
Hehe. That's quite a monster. I'll try to be a bit more helpful.
1. Use loop instead of dotimes so you can make the index range over 1-100 instead of 0-99.
2. Factor out the string calculation so you only need one print statement.
3. Maybe use zerop.
4. Don't write ")(". Use a space in between.
Example:
(loop for n from 1 to 100
do (format t "~a~%"
(cond
((and (zerop (mod n 3))
(zerop (mod n 5)))
"FizzBuzz")
((zerop (mod n 3)) "Fizz")
((zerop (mod n 5)) "Buzz")
(t (format nil "~a" n)))))