Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

In the comments, someone gave this nice solution:

  for x in range(100):
    print x%3/2*'Fizz'+x%5/4*'Buzz' or x+1


That's more like it! First time I heard about Fizzbuzz, I solved it in PHP. I stay amazed at the 100 lines solutions.

for ($i = 1; $i <= 100; $i++) {

    $str = str_repeat('Fizz', !($i%3)&1) . str_repeat('Buzz', !($i%5)&1);

    echo $str ?  "$str\n" : "$i\n";

}




Consider applying for YC's Summer 2026 batch! Applications are open till May 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: