Skip to content

Instantly share code, notes, and snippets.

@runekaagaard
Created August 7, 2012 19:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save runekaagaard/3288593 to your computer and use it in GitHub Desktop.
Save runekaagaard/3288593 to your computer and use it in GitHub Desktop.
FizzBuzz solutions
<?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);
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)
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