Hacker News new | ask | show | jobs
by wrsh07 3683 days ago
One of my friends failed an interview out of college where they asked him fizz buzz, and [using python] he created an array [list(range(1,101))] and then overwrote multiples of 3 with "fizz" multiples of 5 with "buzz" and multiples of 15 with "fizzbuzz."

Because it was an unconventional solution, the interviewer didn't like it.

2 comments

That's exactly how I'd do it! What's supposed to be the better way? Modulo/division by three and five?

    for x in xrange(1,101):
        if not x % 3:
            print "Fizz",
        if not x % 5:
            print "Buzz",
        if (x % 3) and (x % 5):
            print x
        else:
            print ""
>Modulo/division by three and five?

And fifteen.

  for(var i = 1; i <= 100; i++) {
    a[fizz +=3] = "fizz" + (a[fizz] || "");
    a[buzz +=5] = "buzz";
    print(a[i] || i);
  }