Re: A style question
- From: job-271842874@xxxxxxxxxxxxxx
- Date: Tue, 27 Feb 2007 22:30:06 -0500
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.
Otherwise, I am bothered by the spec. Is the FizzBuzz on 15 tied to it factoring to 3 and 5 and those substitutions, or is that coincidental? ie, Could an RFE come thru for 15 to translate to Bang? Also, is this list expected to expand? If so, will the test always be even divisibility?
Yes, the FizzBuzz on 15 is because the spec said to print FizzBuzz instead of i for any i that is divisible by both 3 and 5. Regarding enhancements, I'll be including one in a reply to Paul in a few minutes.
This is how I get thrown out of most tech interviews..
kt
- Follow-Ups:
- Re: A style question
- From: John Thingstad
- Re: A style question
- From: Vassil Nikolov
- Re: A style question
- From: Ken Tilton
- Re: A style question
- References:
- A style question
- From: job-271842874
- Re: A style question
- From: Paul Wallich
- Re: A style question
- From: Ken Tilton
- A style question
- Prev by Date: Re: A style question
- Next by Date: Re: A style question
- Previous by thread: Re: A style question
- Next by thread: Re: A style question
- Index(es):
Relevant Pages
|