Sujet : Re: A style question
De : Nobody447095 (at) *nospam* here-nor-there.org (B. Pym)
Groupes : comp.lang.lispDate : 09. Aug 2024, 09:40:20
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <v94h50$komi$1@dont-email.me>
User-Agent : XanaNews/1.18.1.6
Brian wrote:
(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]
newLISP
(define (fizz)
(define (any _test) (exists _test $args))
(define (divis n) (= 0 (mod i n)))
(for (i 1 21)
(if (divis 3) (print 'fizz))
(if (divis 5) (print 'buzz))
(if (divis 7) (print 'zoom))
(unless (any divis 3 5 7) (print i))
(println)))
(fizz)
1
2
fizz
4
buzz
fizz
zoom
8
fizz
buzz
11
fizz
13
zoom
fizzbuzz
16
17
fizz
19
buzz
fizzzoom