Re: A style question



On Wed, 28 Feb 2007 04:30:06 +0100, <job-271842874@xxxxxxxxxxxxxx> wrote:

Ken Tilton wrote:
Paul Wallich wrote:
job-271842874@xxxxxxxxxxxxxx wrote:

A friend passed on an article regarding the difficulty job candidates had in producing even simple programs (simple as in should take a minute or less). One example was a program to print the numbers 1 to 100 except that "Fizz" should be substituted for numbers divisible by 3, "Buzz" should be substituted for numbers divisible by 5, and "FizzBuzz" should be substituted for numbers divisible by both 3 and 5.

I'd probably brute-force the problem with a simple cond with a nested conditions, along the lines of
(cond ((zerop (mod i 5))
(cond ((zerop (mod i 3)) (print "FizzBuzz"))
(t (print "Buzz"))))
((zerop (mod i 3))
(print "Fizz"))
(t (print i)))
I would object to using cond to implement if, and the redundant code testing for (mod i 3) and associating it with Fizz.

I agree. I expect mod is fast, but I don't like to repeat myself.


rem is fast.. mod conses on fractions on the heap

--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
.