Another update from ingydotnet^djgoku

This commit is contained in:
Ingy döt Net 2015-11-18 06:14:39 +00:00
parent 91df62d461
commit 948b86eafa
7604 changed files with 108452 additions and 22726 deletions

View file

@ -0,0 +1,13 @@
DATA: tab TYPE TABLE OF string.
tab = VALUE #(
FOR i = 1 WHILE i <= 100 (
COND string( LET r3 = i MOD 3
r5 = i MOD 5 IN
WHEN r3 = 0 AND r5 = 0 THEN |FIZZBUZZ|
WHEN r3 = 0 THEN |FIZZ|
WHEN r5 = 0 THEN |BUZZ|
ELSE i ) ) ).
cl_demo_output=>write( tab ).
cl_demo_output=>display( ).

View file

@ -0,0 +1,9 @@
begin
i_w := 1; % set integers to print in minimum space %
for i := 1 until 100 do begin
if i rem 15 = 0 then write( "FizzBuzz" )
else if i rem 5 = 0 then write( "Buzz" )
else if i rem 3 = 0 then write( "Fizz" )
else write( i )
end for_i
end.

View file

@ -0,0 +1 @@
{ 'Fizz' 'Buzz' 'FizzBuzz'[ +/1 2×0=3 5|] }¨1+100

View file

@ -0,0 +1,10 @@
#include <stdio.h>
int main()
{
for (int i=0;++i<101;puts(""))
{
char f[] = "FizzBuzz%d";
f[8-i%5&12]=0;
printf (f+(-i%3&4+f[8]/8), i);
}
}

View file

@ -0,0 +1,26 @@
IDENTIFICATION DIVISION.
PROGRAM-ID. FIZZBUZZ.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 X PIC 999.
01 Y PIC 999.
01 REM3 PIC 999.
01 REM5 PIC 999.
PROCEDURE DIVISION.
PERFORM VARYING X FROM 1 BY 1 UNTIL X > 100
DIVIDE X BY 3 GIVING Y REMAINDER REM3
DIVIDE X BY 5 GIVING Y REMAINDER REM5
EVALUATE REM3 ALSO REM5
WHEN ZERO ALSO ZERO
DISPLAY "FizzBuzz"
WHEN ZERO ALSO ANY
DISPLAY "Fizz"
WHEN ANY ALSO ZERO
DISPLAY "Buzz"
WHEN OTHER
DISPLAY X
END-EVALUATE
END-PERFORM
STOP RUN
.

View file

@ -1,9 +1,9 @@
(defn fizzbuzz [start finish] (map (fn [n]
(defn fizzbuzz [start finish]
(map (fn [n]
(cond
(zero? (mod n 15)) "FizzBuzz"
(zero? (mod n 3)) "Fizz"
(zero? (mod n 5)) "Buzz"
(zero? (mod n 15)) "FizzBuzz"
:else n))
(range start finish))
)
(range start finish)))
(fizzbuzz 1 100)

View file

@ -0,0 +1,4 @@
(take 100
(map #(if (pos? (compare %1 %2)) %1 %2)
(map str (drop 1 (range)))
(map str (cycle ["" "" "Fizz"]) (cycle ["" "" "" "" "Buzz"]))))

View file

@ -0,0 +1,2 @@
(let [n nil fizz (cycle [n n "fizz"]) buzz (cycle [n n n n "buzz"]) nums (iterate inc 1)]
(take 20 (map #(if (or %1 %2) (str %1 %2) %3) fizz buzz nums)))

View file

@ -1,2 +1,10 @@
for i in [1..100]
console.log(['Fizz' if i % 3 is 0] + ['Buzz' if i % 5 is 0] or i)
console.log \
if i % 15 is 0
"FizzBuzz"
else if i % 3 is 0
"Fizz"
else if i % 5 is 0
"Buzz"
else
i

View file

@ -0,0 +1,2 @@
for i in [1..100]
console.log(['Fizz' if i % 3 is 0] + ['Buzz' if i % 5 is 0] or i)

View file

@ -1,4 +1,5 @@
main() {
for(int i=1;i<=100;i++)
print((i%3==0?"Fizz":"")+(i%5==0?"Buzz":"")+(i%3!=0&&i%5!=0?i:""));
for (int i = 1; i <= 100; i++) {
print((i % 3 == 0 ? "Fizz" : "") + (i % 5 == 0 ? "Buzz" : "") + (i % 3 != 0 && i % 5 != 0 ? "$i" : ""));
}
}

View file

@ -1,10 +1,10 @@
class
APPLICATION
inherit
ARGUMENTS
create
make
feature {NONE} -- Initialization
feature
make
do
@ -12,24 +12,22 @@ feature {NONE} -- Initialization
end
fizzbuzz
local
i: INTEGER
do
from
i:= 1
until
i>100
loop
if i\\15= 0 then
io.put_string ("FIZZBUZZ%N")
elseif i\\3=0 then
io.put_string ("FIZZ%N")
elseif i\\5=0 then
io.put_string ("BUZZ%N")
else
io.put_string (i.out + "%N")
--Numbers up to 100, prints "Fizz" instead of multiples of 3, and "Buzz" for multiples of 5.
--For multiples of both 3 and 5 prints "FizzBuzz".
do
across
1 |..| 100 as c
loop
if c.item \\ 15 = 0 then
io.put_string ("FIZZBUZZ%N")
elseif c.item \\ 3 = 0 then
io.put_string ("FIZZ%N")
elseif c.item \\ 5 = 0 then
io.put_string ("BUZZ%N")
else
io.put_string (c.item.out + "%N")
end
end
i:= i+1
end
end
end

View file

@ -1,12 +1,8 @@
Enum.each 1..100, fn x ->
IO.puts(case { rem(x, 5) == 0, rem(x,3) == 0 } do
{ true, true } ->
"FizzBuzz"
{ true, false } ->
"Fizz"
{ false, true } ->
"Buzz"
{ false, false } ->
x
IO.puts(case { rem(x,3) == 0, rem(x,5) == 0 } do
{ true, true } -> "FizzBuzz"
{ true, false } -> "Fizz"
{ false, true } -> "Buzz"
{ false, false } -> x
end)
end

View file

@ -1,13 +1,9 @@
#!/usr/bin/env elixir
1..100 |> Enum.map(fn i ->
cond do
rem(i,3*5) == 0 ->
"fizzbuzz"
rem(i,3) == 0 ->
"fizz"
rem(i,5) == 0 ->
"buzz"
true ->
i
rem(i,3*5) == 0 -> "fizzbuzz"
rem(i,3) == 0 -> "fizz"
rem(i,5) == 0 -> "buzz"
true -> i
end
end) |> Enum.map(fn i -> IO.puts i end)
end) |> Enum.each(fn i -> IO.puts i end)

View file

@ -0,0 +1,14 @@
defmodule RC do
def fizzbuzz(limit \\ 100) do
fizz = Stream.cycle(["", "", "Fizz"])
buzz = Stream.cycle(["", "", "", "", "Buzz"])
Stream.zip(fizz, buzz)
|> Stream.with_index
|> Enum.take(limit)
|> Enum.each(fn {{f,b},i} ->
IO.puts if f<>b=="", do: i+1, else: f<>b
end)
end
end
RC.fizzbuzz

View file

@ -0,0 +1,8 @@
defmodule FizzBuzz do
def fizzbuzz(n) when rem(n, 15) == 0, do: "FizzBuzz"
def fizzbuzz(n) when rem(n, 5) == 0, do: "Buzz"
def fizzbuzz(n) when rem(n, 3) == 0, do: "Fizz"
def fizzbuzz(n), do: n
end
Enum.map(1..100, &FizzBuzz.fizzbuzz/1)

View file

@ -0,0 +1,91 @@
defmodule BadFizz do
# Hand-rolls a bunch of AST before injecting the resulting FizzBuzz code.
defmacrop automate_fizz(fizzers, n) do
# To begin, we need to process fizzers to produce the various components
# we're using in the final assembly. As told by Mickens telling as Antonio
# Banderas, first you must specify a mapping function:
build_parts = (fn {fz, n} ->
ast_ref = {fz |> String.downcase |> String.to_atom, [], __MODULE__}
clist = List.duplicate("", n - 1) ++ [fz]
cycle = quote do: unquote(ast_ref) = unquote(clist) |> Stream.cycle
{ast_ref, cycle}
end)
# ...and then a reducing function:
collate = (fn
({ast_ref, cycle}, {ast_refs, cycles}) ->
{[ast_ref | ast_refs], [cycle | cycles]}
end)
# ...and then, my love, when you are done your computation is ready to run
# across thousands of fizzbuzz:
{ast_refs, cycles} = fizzers
|> Code.eval_quoted([], __ENV__) |> elem(0) # Gotta unwrap this mystery code~
|> Enum.sort(fn ({_, ap}, {_, bp}) -> ap < bp end) # Sort so that Fizz, 3 < Buzz, 5
|> Enum.map(build_parts)
|> Enum.reduce({[], []}, collate)
# Setup the anonymous functions used by Enum.reduce to build our AST components.
# This was previously handled by List.foldl, but ejected because reduce/2's
# default behavior reduces repetition.
#
# ...I was tempted to move these into a macro themselves, and thought better of it.
build_zip = fn (varname, ast) ->
quote do: Stream.zip(unquote(varname), unquote(ast))
end
build_tuple = fn (varname, ast) ->
{:{}, [], [varname, ast]}
end
build_concat = fn (varname, ast) ->
{:<>,
[context: __MODULE__, import: Kernel], # Hygiene values may change; accurate to Elixir 1.1.1
[varname, ast]}
end
# Toss cycles into a block by hand, then smash ast_refs into
# a few different computations on the cycle block results.
cycles = {:__block__, [], cycles}
tuple = ast_refs |> Enum.reduce(build_tuple)
zip = ast_refs |> Enum.reduce(build_zip)
concat = ast_refs |> Enum.reduce(build_concat)
# Finally-- Now that all our components are assembled, we can put
# together the fizzbuzz stream pipeline. After quote ends, this
# block is injected into the caller's context.
quote do
unquote(cycles)
unquote(zip)
|> Stream.with_index
|> Enum.take(unquote(n))
|> Enum.each(fn
{unquote(tuple), i} ->
ccats = unquote(concat)
IO.puts if ccats == "", do: i + 1, else: ccats
end)
end
end
@doc ~S"""
A fizzing, and possibly buzzing function. Somehow, you feel like you've
seen this before. An old friend, suddenly appearing in Kafkaesque nightmare...
...or worse, during a whiteboard interview.
"""
def fizz(n \\ 100) when is_number(n) do
# In reward for all that effort above, we now have the latest in
# programmer productivity:
#
# A DSL for building arbitrary fizzing, buzzing, bazzing, and more!
[{"Fizz", 3},
{"Buzz", 5}#,
#{"Bar", 7},
#{"Foo", 243}, # -> Always printed last (largest number)
#{"Qux", 34}
]
|> automate_fizz(n)
end
end
BadFizz.fizz(100) # => Prints to stdout

View file

@ -1,12 +1,11 @@
program fizzbuzz_select
integer :: i
program FizzBuzz
implicit none
integer :: i = 1
do i = 1, 100
select case (mod(i,15))
case 0; print *, 'FizzBuzz'
case 3,6,9,12; print *, 'Fizz'
case 5,10; print *, 'Buzz'
case default; print *, i
end select
end do
end program fizzbuzz_select
do i = 1, 100
if (Mod(i,3) == 0)write(*,"(A)",advance='no') "Fizz"
if (Mod(i,5) == 0)write(*,"(A)",advance='no') "Buzz"
if (Mod(i,3) /= 0 .and. Mod(i,5) /=0 )write(*,"(I3)",advance='no') i
print *, ""
end do
end program FizzBuzz

View file

@ -0,0 +1,12 @@
program fizzbuzz_select
integer :: i
do i = 1, 100
select case (mod(i,15))
case 0; print *, 'FizzBuzz'
case 3,6,9,12; print *, 'Fizz'
case 5,10; print *, 'Buzz'
case default; print *, i
end select
end do
end program fizzbuzz_select

View file

@ -0,0 +1,7 @@
gen n word = cycle (take (n - 1) (repeat "") ++ [word])
pattern = zipWith (++) (gen 3 "fizz") (gen 5 "buzz")
fizzbuzz = zipWith combine pattern [1..] where
combine word number = if null word
then show number
else word
show $ take 100 fizzbuzz

View file

@ -0,0 +1,16 @@
The space is a room. An item is a kind of thing. In the space are 100 items.
To say the name:
let the count be the number of items carried by the player;
say "[if the count is the count to the nearest 15]fizzbuzz.[otherwise if the count is the count to the nearest 3]fizz.[otherwise if the count is the count to the nearest 5]buzz.[otherwise][the count in words].".
To count:
if an item is in the space
begin;
let the next one be a random item in the space; silently try taking the next one;
say "[the name]" in sentence case;
count;
end the story;
end if.
When play begins: count. Use no scoring.

View file

@ -1,2 +1,2 @@
test =: +/@(1 2 * 0 = 3 5&|~)
(":@]`('Fizz'"_)`('Buzz'"_)`('FizzBuzz'"_) @. test"0) >:i.100
classify =: +/@(1 2 * 0 = 3 5&|~)
(":@]`('Fizz'"_)`('Buzz'"_)`('FizzBuzz'"_) @. classify "0) >:i.100

View file

@ -0,0 +1,2 @@
;:inv}.(":&.> [^:(0 = #@])&.> [: ,&.>/ (;:'Fizz Buzz') #&.>~ 0 = 3 5 |/ ])i.101
1 2 Fizz 4 Buzz Fizz 7 8 Fizz Buzz 11 Fizz 13 14 FizzBuzz 16 17 Fizz 19 Buzz Fizz 22 23 Fizz Buzz 26 Fizz 28 29 FizzBuzz 31 32 Fizz 34 Buzz Fizz 37 38 Fizz Buzz 41 Fizz 43 44 FizzBuzz 46 47 Fizz 49 Buzz Fizz 52 53 Fizz Buzz 56 Fizz 58 59 FizzBuzz 61 62 Fiz...

View file

@ -0,0 +1,36 @@
i.10
0 1 2 3 4 5 6 7 8 9
(3 5 |/ ])i.10
0 1 2 0 1 2 0 1 2 0
0 1 2 3 4 0 1 2 3 4
(0=3 5 |/ ])i.10
1 0 0 1 0 0 1 0 0 1
1 0 0 0 0 1 0 0 0 0
(;:'Fizz Buzz')
┌────┬────┐
│Fizz│Buzz│
└────┴────┘
((;:'Fizz Buzz') #&.>~0=3 5 |/ ])i.10
┌────┬┬┬────┬┬────┬────┬┬┬────┐
│Fizz│││Fizz││ │Fizz│││Fizz│
├────┼┼┼────┼┼────┼────┼┼┼────┤
│Buzz│││ ││Buzz│ │││ │
└────┴┴┴────┴┴────┴────┴┴┴────┘
([: ,&.>/ (;:'Fizz Buzz') #&.>~0=3 5 |/ ])i.10
┌────────┬┬┬────┬┬────┬────┬┬┬────┐
│FizzBuzz│││Fizz││Buzz│Fizz│││Fizz│
└────────┴┴┴────┴┴────┴────┴┴┴────┘
(":&.>)i.10
┌─┬─┬─┬─┬─┬─┬─┬─┬─┬─┐
│0│1│2│3│4│5│6│7│8│9│
└─┴─┴─┴─┴─┴─┴─┴─┴─┴─┘
(":&.> [^:(0 = #@])&.> [: ,&.>/ (;:'Fizz Buzz') #&.>~0=3 5 |/ ])i.10
┌────────┬─┬─┬────┬─┬────┬────┬─┬─┬────┐
│FizzBuzz│1│2│Fizz│4│Buzz│Fizz│7│8│Fizz│
└────────┴─┴─┴────┴─┴────┴────┴─┴─┴────┘
}.(":&.> [^:(0 = #@])&.> [: ,&.>/ (;:'Fizz Buzz') #&.>~0=3 5 |/ ])i.10
┌─┬─┬────┬─┬────┬────┬─┬─┬────┐
│1│2│Fizz│4│Buzz│Fizz│7│8│Fizz│
└─┴─┴────┴─┴────┴────┴─┴─┴────┘
;:inv}.(":&.> [^:(0 = #@])&.> [: ,&.>/ (;:'Fizz Buzz') #&.>~0=3 5 |/ ])i.10
1 2 Fizz 4 Buzz Fizz 7 8 Fizz

View file

@ -1,7 +1,9 @@
var i, output;
for (i = 1; i < 101; i++) {
output = '';
if (!(i % 3)) output += 'Fizz';
if (!(i % 5)) output += 'Buzz';
console.log(output || i);
}
var fizzBuzz = function () {
var i, output;
for (i = 1; i < 101; i += 1) {
output = '';
if (!(i % 3)) { output += 'Fizz'; }
if (!(i % 5)) { output += 'Buzz'; }
console.log(output || i);//empty string is false, so we short-circuit
}
};

View file

@ -1,25 +1,7 @@
var divs = [15, 3, 5];
var says = ['FizzBuzz', 'Fizz', 'Buzz'];
function fizzBuzz(first, last) {
for (var n = first; n <= last; n++) {
print(getFizzBuzz(n));
}
for (var i = 1; i <= 100; i++) {
console.log({
truefalse: 'Fizz',
falsetrue: 'Buzz',
truetrue: 'FizzBuzz'
}[(i%3==0) + '' + (i%5==0)] || i)
}
function getFizzBuzz(n) {
var sayWhat = n;
for (var d = 0; d < divs.length; d++) {
if (isMultOf(n, divs[d])) {
sayWhat = says[d];
break;
}
}
return sayWhat;
}
function isMultOf(n, d) {
return n % d == 0;
}
fizzBuzz(1, 100);

View file

@ -1 +1 @@
for(var i=1; i<=100; console.log((i%3?'':'Fizz')+(i%5?'':'Buzz')||i), i++);
for(i=1;i<101;i++)console.log((x=(i%3?'':'Fizz')+(i%5?'':'Buzz'))?x:i);

View file

@ -1 +1,11 @@
for(i=0;i<100;console.log(++i%15?i%5?i%3?i:f='Fizz':b='Buzz':f+b));
(function rng(i) {
return i ? rng(i - 1).concat(i) : []
})(100).map(
function (n) {
return n % 3 ? (
n % 5 ? n : "Buzz"
) : (
n % 5 ? "Fizz" : "FizzBuzz"
)
}
).join(' ')

View file

@ -0,0 +1,10 @@
public 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)
}
}
}

View file

@ -0,0 +1,15 @@
var i = 1
while(i < 100) {
if(i % 15 == 0) {
$print("FizzBuzz\n");
} else if(i % 3 == 0) {
$print("Fizz\n");
} else if(i % 5 == 0) {
$print("Buzz\n");
} else {
$print(i + "\n");
}
i ++= 1
}

View file

@ -1,4 +1,8 @@
.say for
(('' xx 2, 'Fizz') xx * Z~
('' xx 4, 'Buzz') xx *) Z||
1 .. 100;
(
(flat ('' xx 2, 'Fizz') xx *)
Z~
(flat ('' xx 4, 'Buzz') xx *)
)
Z||
1 .. 100;

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
for i in range(100):print(i%3//2*'Fizz'+i%5//4*'Buzz'or i+1)

View file

@ -1,4 +1,13 @@
print ('\n'.join(''.join(''.join(['' if i%3 else 'Fizz',
'' if i%5 else 'Buzz'])
or str(i))
for i in range(1,101)))
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

View file

@ -0,0 +1 @@
{$[0=x mod 15;"FizzBuzz";0=x mod 5;"Buzz";0=x mod 3;"Fizz";string x]} each 1+til 15

View file

@ -0,0 +1 @@
-1 "\n" sv{$[0=x mod 15;"FizzBuzz";0=x mod 5;"Buzz";0=x mod 3;"Fizz";string x]} each 1+til 15;

View file

@ -1,2 +1,6 @@
x <- paste(rep("", 100), c("", "", "Fizz"), c("", "", "", "", "Buzz"), sep="")
cat(ifelse(x == "", 1:100, x), "\n")
xx <- rep("", 100)
x <- 1:100
xx[x %% 3 == 0] <- paste0(xx[x %% 3 == 0], "Fizz")
xx[x %% 5 == 0] <- paste0(xx[x %% 5 == 0], "Buzz")
xx[xx == ""] <- x[xx == ""]
xx

View file

@ -1,4 +1,2 @@
x <- 1:100
ifelse(x %% 15 == 0, 'FizzBuzz',
ifelse(x %% 5 == 0, 'Buzz',
ifelse(x %% 3 == 0, 'Fizz', x)))
x <- paste(rep("", 100), c("", "", "Fizz"), c("", "", "", "", "Buzz"), sep="")
cat(ifelse(x == "", 1:100, x), "\n")

View file

@ -0,0 +1,4 @@
x <- 1:100
ifelse(x %% 15 == 0, 'FizzBuzz',
ifelse(x %% 5 == 0, 'Buzz',
ifelse(x %% 3 == 0, 'Fizz', x)))

View file

@ -1,8 +1,3 @@
class Integer
def fizzbuzz
v = "#{"Fizz" if self % 3 == 0}#{"Buzz" if self % 5 == 0}"
v.empty? ? self : v
end
end
puts *(1..100).map(&:fizzbuzz)
seq = *0..100
{Fizz:3, Buzz:5, FizzBuzz:15}.each{|k,n| n.step(100,n){|i|seq[i]=k}}
puts seq.drop(1)

View file

@ -1,8 +1,8 @@
fizzbuzz = ->(i) do
(i%15).zero? and next "FizzBuzz"
(i%3).zero? and next "Fizz"
(i%5).zero? and next "Buzz"
i
class Integer
def fizzbuzz
v = "#{"Fizz" if self % 3 == 0}#{"Buzz" if self % 5 == 0}"
v.empty? ? self : v
end
end
puts (1..100).map(&fizzbuzz).join("\n")
puts *(1..100).map(&:fizzbuzz)

View file

@ -0,0 +1,8 @@
fizzbuzz = ->(i) do
(i%15).zero? and next "FizzBuzz"
(i%3).zero? and next "Fizz"
(i%5).zero? and next "Buzz"
i
end
puts (1..100).map(&fizzbuzz).join("\n")

View file

@ -1,5 +1 @@
f = [nil, nil, :Fizz].cycle
b = [nil, nil, nil, nil, :Buzz].cycle
(1..100).each do |i|
puts "#{f.next}#{b.next}"[/.+/] || i
end
1.upto(100){|i|puts'FizzBuzz '[n=i**4%-15,n+13]||i}

View file

@ -1,3 +1,5 @@
seq = *0..100
{Fizz:3, Buzz:5, FizzBuzz:15}.each{|k,n| n.step(100,n){|i|seq[i]=k}}
puts seq.drop(1)
f = [nil, nil, :Fizz].cycle
b = [nil, nil, nil, nil, :Buzz].cycle
(1..100).each do |i|
puts "#{f.next}#{b.next}"[/.+/] || i
end

View file

@ -1,12 +1,13 @@
// rust 0.13
#![feature(into_cow)]
use std::borrow::IntoCow;
fn main() {
for i in range(1i, 101){
let value = i.to_string();
println!("{}", match (i % 3, i % 5) {
(0,0) => "FizzBuzz",
(0,_) => "Fizz",
(_,0) => "Buzz",
_ => value.as_slice()
});
for i in 1..101 {
println!("{}", match (i%3, i%5) {
(0,0) => "FizzBuzz".into_cow(),
(0,_) => "Fizz".into_cow(),
(_,0) => "Buzz".into_cow(),
_ => i.to_string().into_cow(),
});
}
}

View file

@ -1,11 +1,10 @@
// rust 0.11
fn main() {
for num in std::iter::range_inclusive(1i, 100) {
match (num % 3, num % 5) {
(0, 0) => println!("FizzBuzz"),
(0, _) => println!("Fizz"),
(_, 0) => println!("Buzz"),
(_, _) => println!("{}", num),
for i in 1..101 {
match (i % 3 == 0, i % 5 == 0) {
(true, true) => println!("FizzBuzz"),
(true, false) => println!("Fizz"),
(false, true) => println!("Buzz"),
(false, false) => println!("{}", i),
}
}
}

View file

@ -1 +1 @@
for (n <- 1 to 100) println(List((15, "FizzBuzz"), (3, "Fizz"), (5, "Buzz")).find(t => n % t._1 == 0).getOrElse((0, n.toString))._2)
for (i <- 1 to 100) println(Seq(15 -> "FizzBuzz", 3 -> "Fizz", 5 -> "Buzz").find(i % _._1 == 0).map(_._2).getOrElse(i))

View file

@ -0,0 +1,5 @@
def fizzbuzz(l: List[String], n: Int, s: String) = if (l.head.toInt % n == 0) l :+ s else l
def fizz(l: List[String]) = fizzbuzz(l, 3, "Fizz")
def buzz(l: List[String]) = fizzbuzz(l, 5, "Buzz")
def headOrTail(l: List[String]) = if (l.tail.size == 0) l.head else l.tail.mkString
Stream.from(1).take(100).map(n => List(n.toString)).map(fizz).map(buzz).map(headOrTail).foreach(println)

View file

@ -0,0 +1,13 @@
@ n = 1
while ( $n <= 100 )
if ($n % 15 == 0) then
echo FizzBuzz
else if ($n % 5 == 0) then
echo Buzz
else if ($n % 3 == 0) then
echo Fizz
else
echo $n
endif
@ n += 1
end

View file

@ -0,0 +1,22 @@
implement main
open core, console
class predicates
fizzbuzz : (integer) -> string procedure (i).
clauses
fizzbuzz(X) = S :- X mod 15 = 0, S = "FizzBuzz", !.
fizzbuzz(X) = S :- X mod 5 = 0, S = "Buzz", !.
fizzbuzz(X) = S :- X mod 3 = 0, S = "Fizz", !.
fizzbuzz(X) = S :- S = toString(X).
run() :-
foreach X = std::fromTo(1,100) do
write(fizzbuzz(X)), write("\n")
end foreach,
succeed.
end implement main
goal
console::runUtf8(main::run).