Last active
December 16, 2015 19:30
-
-
Save jomido/5485962 to your computer and use it in GitHub Desktop.
General Fizzbuzz II
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def n_of_k(n, k): | |
return lambda n: n % k == 0 | |
def n_for_ks(n, *ks): | |
return [n_of_k(n, k) for k in ks] | |
def test(): | |
conditions = [ | |
([3, 5, 2], lambda n: "WOW!"), | |
([3, 5], lambda n: "FizzBuzz"), | |
([3], lambda n: "Fizz"), | |
([5], lambda n: "Buzz"), | |
([1], lambda n: n) | |
] | |
for n in range(1, 31): | |
for i, c in enumerate(conditions): | |
conds, fn = c | |
if all([f(n) for f in n_for_ks(n, *conds)]): | |
print (fn(n)) | |
break | |
test() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment