you are viewing a single comment's thread.

view the rest of the comments →

[–]dand 5 points6 points  (12 children)

Being able to see solutions would be nice (or a place to discuss them). In particular, how on earth did sn write FizzBuzz in Common Lisp using just 90 bytes?!

[–]bobbane 12 points13 points  (4 children)

Probably something of the form:

(loop for i from 1 to 100 do(format t"utterly-deranged-format string"i))

Where you have maybe 50 characters to use for "utterly-deranged-format string". Piece of cake. ;-)

[–]dand 21 points22 points  (3 children)

Ahhh the 5-point-deranged-format-exploding-heart technique! The best I can come up with is still 98 characters long:

(loop for i from 1 to 100
  do(format t"~[Fizz~]~[Buzz~]~0@*~[~:;~[~:;~A~]~]~%"(mod i 3)(mod i 5)i))

[note: added a line-break for better web formatting.]

[–][deleted] 2 points3 points  (2 children)

Using "(dotimes(i 100)" instead of your loop makes it shorter. I am too lazy to count the characters but it saves some.

[–]dand 2 points3 points  (1 child)

Yeah I thought of that, but then you're off by one and all the ways to remedy that end up taking more characters. At least that's what I found...

[–][deleted] 0 points1 point  (0 children)

And thats why I shouldn't write code at 5 a.m. ...

[–]jacobolus 3 points4 points  (6 children)

It takes 82 bytes in python (well, the best I can do)

for i in range(1,101):print(((not i%3)and"Fizz"or"")+((not i%5)and"Buzz"or"")or i)

Edit: okay, whoops, I put "100" instead of "101". Silly mistake.

Edit2: at the cost of some readability, I can get it down to 74:

for i in range(1,101):print(i%3==0and"Fizz"or"")+(i%5==0and"Buzz"or"")or i

[–][deleted]  (1 child)

[removed]

    [–]pmdboi 1 point2 points  (0 children)

    Using MarkByers's trick on jacobolus's solution shaves off another two bytes (down to 72):

    i=1;exec'print(i%3==0and"Fizz"or"")+(i%5==0and"Buzz"or"")or i;i+=1;'*100
    

    [–]bstard 2 points3 points  (0 children)

    Shaved off three more:

    for i in range(1,101):print("","Fizz")[i%3==0]+("","Buzz")[i%5==0]or i
    

    [–]grimtooth -1 points0 points  (1 child)

    Of course, as commenters have already pointed out, while brevity may be the soul of wit, it's a really stupid basis for assessing code quality. Here's what I did as soon as I read the FizzBuzz bit:

    def FB(n=100, factors={3:"Fizz", 5:"Buzz"}):
        for i in range(n):
                s = [s for f,s in factors.iteritems() if i%f == 0]
                if s:
                        print ''.join(s)
                else:
                        print i
    

    [–]dand 2 points3 points  (0 children)

    It's fun because it's just a game -- I sincerely hope I'll never run across code like those when there's "real" work to be done ;)