Family Day update

This commit is contained in:
Ingy döt Net 2020-02-17 23:21:07 -08:00
parent aac6731f2c
commit 9ad63ea473
2442 changed files with 39761 additions and 8255 deletions

View file

@ -0,0 +1,12 @@
1.upto(100) do |n|
case
when n % 15 == 0
puts "FizzBuzz"
when n % 5 == 0
puts "Buzz"
when n % 3 == 0
puts "Fizz"
else
puts n
end
end

View file

@ -1,7 +1,8 @@
-spec fizzbuzz() -> Result :: string().
fizzbuzz() ->
F = fun(N) when N rem 15 == 0 -> "FizzBuzz";
(N) when N rem 3 == 0 -> "Fizz";
(N) when N rem 5 == 0 -> "Buzz";
(N) -> integer_to_list(N)
end,
[F(N)++"\n" || N <- lists:seq(1,100)].
lists:flatten([[F(N)] ++ ["\n"] || N <- lists:seq(1,100)]).

View file

@ -1,16 +1,14 @@
class FizzBuzz {
public class FizzBuzz {
public static void main(String[] args) {
for (int i = 1; i < 101; i++) {
if ((i % 3 == 0) && (i % 5 == 0)) {
System.out.print("'fizz buzz', ");
} else if (i % 3 == 0) {
System.out.print("'fizz', ");
} else if (i % 5 == 0) {
System.out.print("'buzz', ");
for (int number = 1; number <= 100; number++) {
if (number % 15 == 0) {
System.out.println("FizzBuzz");
} else if (number % 3 == 0) {
System.out.println("Fizz");
} else if (number % 5 == 0) {
System.out.println("Buzz");
} else {
System.out.printf("%d, ", i);
System.out.println(number);
}
}
}

View file

@ -1,10 +1,12 @@
fun fizzBuzz() {
for (i in 1..100) {
when {
i % 15 == 0 -> println("FizzBuzz")
i % 3 == 0 -> println("Fizz")
i % 5 == 0 -> println("Buzz")
else -> println(i)
}
for (number in 1..100) {
println(
when {
number % 15 == 0 -> "FizzBuzz"
number % 3 == 0 -> "Fizz"
number % 5 == 0 -> "Buzz"
else -> number
}
)
}
}

View file

@ -1,3 +1,3 @@
fun fizzBuzz() {
println((1..100).map{i->mapOf(0 to i,i%3 to "Fizz",i%5 to "Buzz",i%15 to "FizzBuzz")[0]})
(1..100).forEach { println(mapOf(0 to it, it % 3 to "Fizz", it % 5 to "Buzz", it % 15 to "FizzBuzz")[0]) }
}

View file

@ -0,0 +1,20 @@
#!/usr/bin/env luajit
local to=arg[1] or tonumber(arg[1]) or 100
local CF,CB=3,5
local cf,cb=CF,CB
for i=1,to do
cf,cb=cf-1,cb-1
if cf~=0 and cb~=0 then
io.write(i)
else
if cf==0 then
cf=CF
io.write("Fizz")
end
if cb==0 then
cb=CB
io.write("Buzz")
end
end
io.write(", ")
end

View file

@ -1,11 +1,10 @@
for(int i = 1; i <= 100; i++){
String output = "";
if(i % 3 == 0) output += "Fizz";
if(i % 5 == 0) output += "Buzz";
// copy & paste above line to add more tests
if(output == "") output = int(i);
println(output);
}
String output = "";
if(i % 3 == 0) output += "Fizz";
if(i % 5 == 0) output += "Buzz";
// copy & paste above line to add more tests
if(output == "") output = str(i);
println(output);
}

View file

@ -1 +1,52 @@
print(*map(lambda n: 'Fizzbuzz '[(i):i+13] if (i := n**4%-15) > -14 else n, range(1,100)))
'''Fizz buzz'''
from itertools import count, cycle, islice
# fizzBuzz :: () -> Generator [String]
def fizzBuzz():
'''A non-finite stream of fizzbuzz terms.'''
return map(
lambda f, b, n: (f + b) or n,
cycle([''] * 2 + ['Fizz']),
cycle([''] * 4 + ['Buzz']),
map(str, count(1))
)
# main :: IO ()
def main():
'''Display of first 100 terms of the fizzbuzz series.
'''
print(unlines(
take(100)(
fizzBuzz()
)
))
# GENERIC -------------------------------------------------
# take :: Int -> [a] -> [a]
# take :: Int -> String -> String
def take(n):
'''The prefix of xs of length n,
or xs itself if n > length xs.
'''
return lambda xs: (
xs[0:n]
if isinstance(xs, (list, tuple))
else list(islice(xs, n))
)
# unlines :: [String] -> String
def unlines(xs):
'''A single string formed by the intercalation
of a list of strings with the newline character.
'''
return '\n'.join(xs)
if __name__ == '__main__':
main()

View file

@ -0,0 +1 @@
print(*map(lambda n: 'Fizzbuzz '[(i):i+13] if (i := n**4%-15) > -14 else n, range(1,100)))

View file

@ -0,0 +1,12 @@
def numsum(n):
''' The recursive sum of all digits in a number
unit a single character is obtained'''
res = sum([int(i) for i in str(n)])
if res < 10: return res
else : return numsum(res)
for n in range(1,101):
response = 'Fizz'*(numsum(n) in [3,6,9]) + \
'Buzz'*(str(n)[-1] in ['5','0'])\
or n
print(response)

View file

@ -1 +1,9 @@
for i in range(1,101): print("Fizz"*(i%3==0) + "Buzz"*(i%5==0) or i)
for n in range(1,101):
response = ''
if not n%3:
response += 'Fizz'
if not n%5:
response += 'Buzz'
print(response or n)

View file

@ -1 +1 @@
for i in range(100):print(i%3//2*'Fizz'+i%5//4*'Buzz'or i+1)
for i in range(1,101): print("Fizz"*(i%3==0) + "Buzz"*(i%5==0) or i)

View file

@ -1,3 +1 @@
for n in range(1, 100):
fb = ''.join([ denom[1] if n % denom[0] == 0 else '' for denom in [(3,'fizz'),(5,'buzz')] ])
print fb if fb else n
for i in range(100):print(i%3//2*'Fizz'+i%5//4*'Buzz'or i+1)

View file

@ -1 +1,3 @@
print (', '.join([(x%3<1)*'Fizz'+(x%5<1)*'Buzz' or str(x) for x in range(1,101)]))
for n in range(1, 100):
fb = ''.join([ denom[1] if n % denom[0] == 0 else '' for denom in [(3,'fizz'),(5,'buzz')] ])
print fb if fb else n

View file

@ -1 +1 @@
[print("FizzBuzz") if i % 15 == 0 else print("Fizz") if i % 3 == 0 else print("Buzz") if i % 5 == 0 else print(i) for i in range(1,101)]
print (', '.join([(x%3<1)*'Fizz'+(x%5<1)*'Buzz' or str(x) for x in range(1,101)]))

View file

@ -1,13 +1 @@
from itertools import cycle, izip, count, islice
fizzes = cycle([""] * 2 + ["Fizz"])
buzzes = cycle([""] * 4 + ["Buzz"])
both = (f + b for f, b in izip(fizzes, buzzes))
# if the string is "", yield the number
# otherwise yield the string
fizzbuzz = (word or n for word, n in izip(both, count(1)))
# print the first 100
for i in islice(fizzbuzz, 100):
print i
[print("FizzBuzz") if i % 15 == 0 else print("Fizz") if i % 3 == 0 else print("Buzz") if i % 5 == 0 else print(i) for i in range(1,101)]

View file

@ -1,52 +1,13 @@
'''Fizz buzz'''
from itertools import cycle, izip, count, islice
from itertools import count, cycle, islice
fizzes = cycle([""] * 2 + ["Fizz"])
buzzes = cycle([""] * 4 + ["Buzz"])
both = (f + b for f, b in izip(fizzes, buzzes))
# if the string is "", yield the number
# otherwise yield the string
fizzbuzz = (word or n for word, n in izip(both, count(1)))
# fizzBuzz :: () -> Generator [String]
def fizzBuzz():
'''A non-finite stream of fizzbuzz terms.'''
return map(
lambda f, b, n: (f + b) or n,
cycle([''] * 2 + ['Fizz']),
cycle([''] * 4 + ['Buzz']),
map(str, count(1))
)
# main :: IO ()
def main():
'''Display of first 100 terms of the fizzbuzz series.
'''
print(unlines(
take(100)(
fizzBuzz()
)
))
# GENERIC -------------------------------------------------
# take :: Int -> [a] -> [a]
# take :: Int -> String -> String
def take(n):
'''The prefix of xs of length n,
or xs itself if n > length xs.
'''
return lambda xs: (
xs[0:n]
if isinstance(xs, (list, tuple))
else list(islice(xs, n))
)
# unlines :: [String] -> String
def unlines(xs):
'''A single string formed by the intercalation
of a list of strings with the newline character.
'''
return '\n'.join(xs)
if __name__ == '__main__':
main()
# print the first 100
for i in islice(fizzbuzz, 100):
print i

View file

@ -0,0 +1,29 @@
entity fizzbuzz is
end entity fizzbuzz;
architecture beh of fizzbuzz is
procedure fizzbuzz(num : natural) is
begin
if num mod 15 = 0 then
report "FIZZBUZZ";
elsif num mod 3 = 0 then
report "FIZZ";
elsif num mod 5 = 0 then
report "BUZZ";
else
report to_string(num);
end if;
end procedure fizzbuzz;
begin
p_fizz : process is
begin
for i in 1 to 100 loop
fizzbuzz(i);
end loop;
wait for 200 us;
end process p_fizz;
end architecture beh;