Created
August 7, 2012 19:23
-
-
Save runekaagaard/3288593 to your computer and use it in GitHub Desktop.
FizzBuzz solutions
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
<?php | |
function fizzbuzz($n) { | |
for ($f=$b=$i=1; | |
$i<=$n; | |
$line = '', | |
($f==3 && !$f=0) ? $line = "Fizz" : null, | |
($b==5 && !$b=0) ? $line .= "Buzz" : null, | |
print ($line !== '' ? $line : $i) . "\n", | |
++$f,++$b,++$i | |
); | |
} | |
fizzbuzz(100); |
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
local F = {'Fizz', 'Buzz', 'FizzBuzz'} | |
local function fizzbuzz(n) | |
for i=1,n do | |
local x = math.floor(math.abs(math.cos(2 * math.pi * i / 3))) | |
+ math.floor(math.abs(math.cos(2 * math.pi * i / 5))) * 2 | |
print (F[x] or i) | |
end | |
end | |
fizzbuzz(100) |
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
F = 'Fizz' | |
B = 'Buzz' | |
U = F + B | |
N = None | |
# 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 | |
sieve = [N,N,F,N,B,F,N,N,F,B,N,F,N,N,U] | |
def fizzbuzz(n): | |
offset = 0 | |
while True: | |
for i in xrange(0,15): | |
value = sieve[i] | |
count = i+1+offset | |
if count > n: | |
return | |
print value if value else count | |
offset += 15 | |
fizzbuzz(100) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment