[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.lisp

Re: A style question

William James

11/10/2015 5:25:00 PM

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]

MatzLisp (Ruby):

def fizzbuzz n
puts (1..n).map{|i| [:fizzbuzz, :buzz, :fizz, i][(i%3<=>0)+2*(i%5<=>0)]}
end

fizzbuzz 15
1
2
fizz
4
buzz
fizz
7
8
fizz
buzz
11
fizz
13
14
fizzbuzz

--
For two years ... he was held in solitary confinement in the Toronto West
Detention Centre, on the pretext that he is a threat to national security....
[A] court in Mannheim sentenced him to five years imprisonment for the crime of
"popular incitement" under Germany's notorious "Holocaust denial" statute.
http://www.revisionists.com/revisionists/z...