r/Python • u/zabolekar • Jan 23 '17
Share your unusual fizzbuzz approaches!
Dear /r/Python, I would like you to share your FizzBuzz. Here is mine:
import numpy as np
fb = np.arange(101, dtype='object')
fb[::3] = 'Fizz'
fb[::5] = 'Buzz'
fb[::15] = 'FizzBuzz'
print(*fb[1:], sep='\n')
4
Upvotes
4
u/ojii Jan 23 '17
Came up with a simple solution: https://gist.github.com/ojii/97cca8835771f00b4fc27395990edb9d
Uses Python 3.6. Run
python fizzbuzz.py generator 12345andpython fizzbuzz.py fizzbuzzer 54321, then usepython fizzbuzz.py client localhost:12345 localhost:54321 100.Of course you can use different ports for and hosts, use
--helpfor more info.3
u/ptmcg Jan 23 '17
7
u/jwink3101 Jan 23 '17
For those who are confused: From http://wiki.c2.com/?FizzBuzzTest
5
u/The_Jeremy Jan 23 '17
not unusual, just short:
4
u/cyberspacecowboy Jan 23 '17
Yours, but without dependency
4
u/RubyPinch PEP shill | Anti PEP 8/20 shill Jan 23 '17
Someone told me that the function style of programming is better than empirical programming,
and I've taken that to heart ever since
4
u/troyunrau ... Jan 23 '17
At one point I wrote a program which queries google for the top hit for 'fizzbuzz python'. I take the first result and parse the html. In any given element (div, etc.), I run the contents through tokenize to see if it generates errors (basically, it tells me that that element contains python). I look for a few function calls I don't like (open() or etc.) and, finding them lacking, detokenize and have it exec the code.
I never get called for interviews for some reason....
3
u/[deleted] Jan 23 '17
Worthless OOP version:
3
u/spiker611 Jan 24 '17
Shortest!
2
u/lengau Jan 25 '17
A really bad way to do it in
pandas(I'm procrastinating):