r/programmingchallenges • • May 02 '11

Challenge: FizzBuzz!

Pick a language. Write this:

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".

http://www.codinghorror.com/blog/2007/02/why-cant-programmers-program.html

10 Upvotes

30 comments sorted by

View all comments

Show parent comment

1

u/mastokhiar Sep 09 '11

Common Lisp using functional style with MAPCAR:

(mapcar
 #'(lambda (n)
     (format t "~A~%"
          (cond 
	    ((zerop (mod n 15)) "FizzBuzz")
	    ((zerop (mod n 3)) "Fizz")
	    ((zerop (mod n 5)) "Buzz")
	    (t n)))) 
 (loop for i from 1 to 100 collect i))