Re: A style question
- From: "John Thingstad" <john.thingstad@xxxxxxxxx>
- Date: Wed, 28 Feb 2007 12:26:18 +0100
On Wed, 28 Feb 2007 04:30:06 +0100, <job-271842874@xxxxxxxxxxxxxx> wrote:
Ken Tilton wrote:Paul Wallich wrote:job-271842874@xxxxxxxxxxxxxx wrote:I would object to using cond to implement if, and the redundant code testing for (mod i 3) and associating it with Fizz.
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 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/
.
- References:
- A style question
- From: job-271842874
- Re: A style question
- From: Paul Wallich
- Re: A style question
- From: Ken Tilton
- Re: A style question
- From: job-271842874
- A style question
- Prev by Date: Lisp as an ODBC data source
- Next by Date: Re: Lisp as an ODBC data source
- Previous by thread: Re: A style question
- Next by thread: Re: A style question
- Index(es):