Re: A style question
- From: Ken Tilton <kentilton@xxxxxxxxx>
- Date: Wed, 28 Feb 2007 01:30:42 -0500
job-271842874@xxxxxxxxxxxxxx wrote:
job-271842874@xxxxxxxxxxxxxx wrote:
def fizz_buzz n
1.upto(n) do |i|
print "Fizz" if fizz = (i % 3) == 0
print "Buzz" if buzz = (i % 5) == 0
puts fizz || buzz ? "" : i
end
end
fizz_buzz 100
(defun fizz-buzz (n)
(do ((i 1 (+ i 1)))
((> i n))
(let
((fizz (= 0 (mod i 3)))
(buzz (= 0 (mod i 5))))
(if fizz (format t "Fizz"))
(if buzz (format t "Buzz"))
(format t "~A~%"
(if (or fizz buzz) "" i)))))
(fizz-buzz 100)
Another friend of mine commenting on the same FizzBuzz thread supplied the following Python code. It certainly is concise:
for i in xrange(1,101):
print(str(i), "Fizz", "Buzz", "FizzBuzz")[(i%3==0)|(i%5==0)<<1]
But this is a programming disaster, stupid pet trick atop stupid pet trick. It collapses in a heap the minute anything changes. It builds into itself all sorts of things that just happen to be true. You have missed that what I am driving at is good programming, you are caught up in cleverness, the road to hell in programming.
Let me help you. If, as it seems, the spec is that FizzBuzz is not accidentally Fizz and Buzz together, then the strings Fizz and Buzz must appear only once in the program, as must the tests (mod x 3) and (mod x 5).
The punch line is that no good programmer could write anything in five minutes, unless the instructions included: "Just frickin make these results appear from this input."
kt
--
Well, I've wrestled with reality for 35 years, Doctor, and
I'm happy to state I finally won out over it.
-- Elwood P. Dowd
In this world, you must be oh so smart or oh so pleasant.
-- Elwood's Mom
.
- Follow-Ups:
- Re: A style question
- From: Brian Adkins
- Re: A style question
- References:
- A style question
- From: job-271842874
- Re: A style question
- From: job-271842874
- A style question
- Prev by Date: Re: sexp-aware theory of patches and "meta common lisp"
- 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
|