Skip to content

Instantly share code, notes, and snippets.

@eidolonrage
Created June 14, 2014 01:05
Show Gist options
  • Save eidolonrage/6baaaa1eebb511fea46f to your computer and use it in GitHub Desktop.
Save eidolonrage/6baaaa1eebb511fea46f to your computer and use it in GitHub Desktop.
Nathan's FizzBuzz thingy
x = 1
for x in range(1,101):
y = x%3
z = x%5
if y + z == 0:
print 'FizzBuzz'
else:
if y == 0:
print 'Fizz'
else:
if z == 0:
print 'Buzz'
else:
print x
@sunetos
Copy link

sunetos commented Jun 14, 2014

To be a jerk, I wrote the most obfuscated (and short) one I could come up with:

for x in xrange(100): print [x + 1, 'Fizz', 'Buzz', 'FizzBuzz'][0x30490610>>x%15*2&3]

@eidolonrage
Copy link
Author

lol what the dick?

It certainly looks shorter. I assume the indecipherable bit at the end is the important part...

Edit: I ran it just to see and it, unsurprisingly, works. How the hell? I see something resembling math at the end, but what's the 0x30490610 thing?

@sunetos
Copy link

sunetos commented Jun 14, 2014

There's quite a bit happening in that one line. I split it up into a much longer version with heavy comments explaining how it works:
https://gist.github.com/sunetos/220d770a7080f9ac38c0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment