Add tasks for all the new languages

This commit is contained in:
Tina Müller 2016-12-05 23:44:36 +01:00
parent 9dc3c2bb62
commit bba7bfd280
13208 changed files with 134745 additions and 0 deletions

View file

@ -0,0 +1,25 @@
with: n
: num? \ n f -- )
if drop else . then ;
\ is m mod n 0? leave the result twice on the stack
: div? \ m n -- f f
mod 0 = dup ;
: fizz? \ n -- n f
dup 3
div? if "Fizz" . then ;
: buzz? \ n f -- n f
over 5
div? if "Buzz" . then or ;
\ print a message as appropriate for the given number:
: fizzbuzz \ n --
fizz? buzz? num?
space ;
\ iterate from 1 to 100:
' fizzbuzz 1 100 loop
cr bye

View file

@ -0,0 +1,3 @@
n:{1+ x}map range[100]
s:{a:0eq x mod 3;b:0eq x mod 5;concat apply{1elem x}map{0elem x}hfilter seq[1- max[a;b];a;b]merge seq[str[x];"Fizz";"Buzz"]}map n
echo map s

View file

@ -0,0 +1,6 @@
(for n 1 100
(prn:if
(multiple n 15) 'FizzBuzz
(multiple n 5) 'Buzz
(multiple n 3) 'Fizz
n))

View file

@ -0,0 +1,4 @@
(for n 1 100
(prn:check (string (when (multiple n 3) 'Fizz)
(when (multiple n 5) 'Buzz))
~empty n)) ; check created string not empty, else return n

View file

@ -0,0 +1,6 @@
(for n 1 100
(prn:case (gcd n 15)
1 n
3 'Fizz
5 'Buzz
'FizzBuzz))

View file

@ -0,0 +1,13 @@
For(I,1,100)
!If I^3??I^5
Disp "FIZZBUZZ",i
Else!If I^3
Disp "FIZZ",i
Else!If I^5
Disp "BUZZ",i
Else
Disp I▶Dec,i
End
.Pause to allow the user to actually read the output
Pause 1000
End

View file

@ -0,0 +1 @@
shared void run() => {for (i in 1..100) {for (j->k in [3->"Fizz", 5->"Buzz"]) if (j.divides(i)) k}.reduce(plus) else i}.each(print);

View file

@ -0,0 +1,6 @@
for i from 1 to 100
console.log do
if i % 15 == 0 then 'FizzBuzz'
else if i % 3 == 0 then 'Fizz'
else if i % 5 == 0 then 'Buzz'
else i

View file

@ -0,0 +1,2 @@
for i from 1 to 100
console.log(['Fizz' unless i % 3] + ['Buzz' unless i % 5] or String(i))

View file

@ -0,0 +1,11 @@
1.upto(100) do |v|
p fizz_buzz(v)
end
def fizz_buzz(value)
word = ""
word += "fizz" if value % 3 == 0
word += "buzz" if value % 5 == 0
word += value.to_s if word.empty?
word
end

View file

@ -0,0 +1,17 @@
DataRec := RECORD
STRING s;
END;
DataRec MakeDataRec(UNSIGNED c) := TRANSFORM
SELF.s := MAP
(
c % 15 = 0 => 'FizzBuzz',
c % 3 = 0 => 'Fizz',
c % 5 = 0 => 'Buzz',
(STRING)c
);
END;
d := DATASET(100,MakeDataRec(COUNTER));
OUTPUT(d);

View file

@ -0,0 +1,17 @@
PROGRAM FIZZ_BUZZ
!
! for rosettacode.org
!
BEGIN
FOR A=1 TO 100 DO
IF A MOD 15=0 THEN
PRINT("FizzBuzz")
ELSIF A MOD 3=0 THEN
PRINT("Fizz")
ELSIF A MOD 5=0 THEN
PRINT("Buzz")
ELSE
PRINT(A)
END IF
END FOR
END PROGRAM

View file

@ -0,0 +1,14 @@
#import <Foundation/Foundation.h>
int main()
autoreleasepool
for int i in 1 .. 100
s := ''
if i % 3 == 0
s << 'Fizz'
if i % 5 == 0
s << 'Buzz'
Log( '(%d) %@', i, s )
return 0

View file

@ -0,0 +1,15 @@
import Graphics.Element exposing (show)
import List exposing (map)
main =
map getWordForNum [1..100] |> show
getWordForNum num =
if num % 15 == 0 then
"FizzBuzz"
else if num % 3 == 0 then
"Fizz"
else if num % 5 == 0 then
"Buzz"
else
toString num

View file

@ -0,0 +1,18 @@
import Html exposing (text)
import List exposing (map)
import String exposing (join)
main : Html.Html
main =
map fizzbuzz [1..100] |> join " " |> text
fizzbuzz : Int -> String
fizzbuzz num =
let
fizz = if num % 3 == 0 then "Fizz" else ""
buzz = if num % 5 == 0 then "Buzz" else ""
in
if fizz == buzz then
toString num
else
fizz ++ buzz

View file

@ -0,0 +1,16 @@
01.10 FOR I=1,100; DO 2.0
01.20 QUIT
02.10 SET ZB=I/15 - FITR(I/15)
02.20 IF (ZB) 2.4, 2.3, 2.4
02.30 TYPE "FizzBuzz" !
02.35 RETURN
02.40 SET Z=I/3 - FITR(I/3)
02.50 IF (Z) 2.7, 2.6, 2.7
02.60 TYPE "Fizz" !
02.65 RETURN
02.70 SET B=I/5 - FITR(I/5)
02.80 IF (B) 2.99, 2.9, 2.99
02.90 TYPE "Buzz" !
02.95 RETURN
02.99 TYPE %3, I, !

View file

@ -0,0 +1,15 @@
include "ConsoleWindow"
dim as short fizz, buzz, i
dim as Str15 s
for i = 1 to 100
fizz = (i mod 3 )
buzz = (i mod 5 )
if (i)
if fizz + buzz == 0 then print i; ".", "FizzBuzz" : exit if
if fizz == 0 then print i; ".", "Fizz" : exit if
if buzz == 0 then print i; ".", "Buzz" : exit if
print i
end if
next i

View file

@ -0,0 +1,13 @@
' Fizz Buzz
'
FOR i%=1 TO 100
IF i% MOD 15=0
PRINT "FizzBuzz"
ELSE IF i% MOD 3=0
PRINT "Fizz"
ELSE IF i% MOD 5=0
PRINT "Buzz"
ELSE
PRINT i%
ENDIF
NEXT i%

View file

@ -0,0 +1,11 @@
:- %say
|= [^ ~ ~]
:- %noun
%+ turn (gulf [1 101])
|= a=@
=+ q=[=(0 (mod a 3)) =(0 (mod a 5))]
?+ q <a>
[& &] "FizzBuzz"
[& |] "Fizz"
[| &] "Buzz"
==

View file

@ -0,0 +1,5 @@
(for [i (range 1 101)] (print (cond
[(not (% i 15)) "FizzBuzz"]
[(not (% i 5)) "Buzz"]
[(not (% i 3)) "Fizz"]
[True i])))

View file

@ -0,0 +1,13 @@
software {
for i over [1,100]
if i mod 15 = 0
print("FizzBuzz")
elseif i mod 3 = 0
print("Fizz")
elseif i mod 5 = 0
print("Buzz")
else
print(i)
end
end
}

View file

@ -0,0 +1,8 @@
fizzBuzz : Nat -> String
fizzBuzz n = if (n `mod` 15) == 0 then "FizzBuzz"
else if (n `mod` 3) == 0 then "Fizz"
else if (n `mod` 5) == 0 then "Buzz"
else show n
main : IO ()
main = sequence_ $ map (putStrLn . fizzBuzz) [1..100]

View file

@ -0,0 +1,20 @@
# FizzBuzz
log_stderror=yes
loadmodule "pv"
loadmodule "xlog"
route {
$var(i) = 1;
while ($var(i) <= 1000) {
if ($var(i) mod 15 == 0) {
xlog("FizzBuzz\n");
} else if ($var(i) mod 5 == 0) {
xlog("Buzz\n");
} else if ($var(i) mod 3 == 0) {
xlog("Fizz\n");
} else {
xlog("$var(i)\n");
}
$var(i) = $var(i) + 1;
}
}

View file

@ -0,0 +1,11 @@
{[fizzy buzzy fizzybuzzy];
fizzy::x!3;
buzzy::x!5;
fizzybuzzy::(fizzy+buzzy);
:[0=fizzybuzzy;.d("FizzBuzz")
:|0=fizzy;
.d("Fizz")
:|0=buzzy;
.d("Buzz");
.d(x)];
.d(" ")}'1+!100

View file

@ -0,0 +1,2 @@
with i in generateSeries(1, 100)
select ((#i % 3 == 0 ? 'Fizz' | '') + (#i % 5 == 0 ? 'Buzz' | '') || #i)

View file

@ -0,0 +1,16 @@
repeat with i = 1 to 100
switch
case i mod 15 = 0
put "FizzBuzz" & cr after fizzbuzz
break
case i mod 5 = 0
put "Buzz" & cr after fizzbuzz
break
case i mod 3 = 0
put "Fizz" & cr after fizzbuzz
break
default
put i & cr after fizzbuzz
end switch
end repeat
put fizzbuzz

View file

@ -0,0 +1 @@
[1 to 100] map -> [k + \zz for k, v of {Fi: 3, Bu: 5} | it % v < 1] * '' || it

View file

@ -0,0 +1,6 @@
include "std.lobster"
forbias(100, 1) i:
fb := (i % 3 == 0 and "fizz" or "") +
(i % 5 == 0 and "buzz" or "")
print fb.length and fb or "" + i

View file

@ -0,0 +1,6 @@
for i in range(1,101) do (
if i%15 == 0 then print("FizzBuzz")
else if i%3 == 0 then print("Fizz")
else if i%5 == 0 then print("Buzz")
else print(i)
)

View file

@ -0,0 +1,13 @@
def fizzBuzz(top):
var t := 1
while (t < top):
if ((t % 3 == 0) || (t % 5 == 0)):
if (t % 15 == 0):
traceln(`$t FizzBuzz`)
else if (t % 3 == 0):
traceln(`$t Fizz`)
else:
traceln(`$t Buzz`)
t += 1
fizzBuzz(100)

View file

@ -0,0 +1,4 @@
for i = 1,100
print ((a) -> a == "" and i or a) table.concat {
i % 3 == 0 and "Fizz" or ""
i % 5 == 0 and "Buzz" or ""}

View file

@ -0,0 +1,12 @@
for i := 1 to 100 do
begin
if i mod 15 = 0 then
print("FizzBuzz")
else if i mod 3 = 0 then
print("Fizz")
else if i mod 5 = 0 then
print("Buzz")
else
print(i);
print("\n")
end

View file

@ -0,0 +1,9 @@
for i in 1..100:
if i mod 15 == 0:
echo("FizzBuzz")
elif i mod 3 == 0:
echo("Fizz")
elif i mod 5 == 0:
echo("Buzz")
else:
echo(i)

View file

@ -0,0 +1,6 @@
var messages = @["", "Fizz", "Buzz", "FizzBuzz"]
var acc = 810092048
for i in 1..100:
var c = acc and 3
echo(if c == 0: $i else: messages[c])
acc = acc shr 2 or c shl 28

View file

@ -0,0 +1,17 @@
import macros
macro FizzBuzz(N): stmt =
var source = ""
for i in 1..N.intVal:
source &= "echo \""
if i mod 15 == 0:
source &= "FizzBuzz"
elif i mod 3 == 0:
source &= "Fizz"
elif i mod 5 == 0:
source &= "Buzz"
else:
source &= $i
source &= "\"\n"
result = parseStmt(source)
FizzBuzz(100)

View file

@ -0,0 +1,8 @@
: fizzbuzz
| i |
100 loop: i [
null
i 3 mod ifZero: [ "Fizz" + ]
i 5 mod ifZero: [ "Buzz" + ]
dup ifNull: [ drop i ] .
] ;

View file

@ -0,0 +1,22 @@
module fizzbuzz;
extern printf;
@Integer main [
var i = 1;
while (i <= 100) {
if (i % 15 == 0)
printf("FizzBuzz");
else if (i % 3 == 0)
printf("Fizz");
else if (i % 5 == 0)
printf("Buzz");
else
printf("%d", i);
printf("\n");
i = i::inc;
}
return 0;
]

View file

@ -0,0 +1,9 @@
<# DEFINE USERDEFINEDROUTINE LITERAL>__FizzBuzz|<# SUPPRESSAUTOMATICWHITESPACE>
<# TEST ISITMODULUSZERO PARAMETER LITERAL>1|3</#>
<# TEST ISITMODULUSZERO PARAMETER LITERAL>1|5</#>
<# ONLYFIRSTOFLASTTWO><# SAY LITERAL>Fizz</#></#>
<# ONLYSECONDOFLASTTWO><# SAY LITERAL>Buzz</#></#>
<# BOTH><# SAY LITERAL>FizzBuzz</#></#>
<# NEITHER><# SAY PARAMETER>1</#></#>
</#></#>
<# ITERATE FORITERATION LITERAL LITERAL>100|<# ACT USERDEFINEDROUTINE POSITION FORITERATION>__FizzBuzz|...</#> </#>

View file

@ -0,0 +1,9 @@
<@ DEFUDRLIT>__FizzBuzz|<@ SAW>
<@ TSTMD0PARLIT>1|3</@>
<@ TSTMD0PARLIT>1|5</@>
<@ O12><@ SAYLIT>Fizz</@></@>
<@ O22><@ SAYLIT>Buzz</@></@>
<@ BTH><@ SAYLIT>FizzBuzz</@></@>
<@ NTH><@ SAYPAR>1</@></@>
</@></@>
<@ ITEFORLITLIT>100|<@ ACTUDRPOSFOR>__FizzBuzz|...</@> </@>

View file

@ -0,0 +1,4 @@
constant x = {"%d\n","Fizz\n","Buzz\n","FizzBuzz\n"}
for i=1 to 100 do
printf(1,x[1+(remainder(i,3)=0)+2*(remainder(i,5)=0)],i)
end for

View file

@ -0,0 +1,18 @@
use "collections"
actor Main
new create(env: Env) =>
for i in Range[I32](1, 100) do
env.out.print(fizzbuzz(i))
end
fun fizzbuzz(n: I32): String =>
if (n % 15) == 0 then
"FizzBuzz"
elseif (n % 5) == 0 then
"Buzz"
elseif (n % 3) == 0 then
"Fizz"
else
n.string()
end

View file

@ -0,0 +1,9 @@
1 to 100 (a):
if (a % 15 == 0):
'FizzBuzz'.
elsif (a % 3 == 0):
'Fizz'.
elsif (a % 5 == 0):
'Buzz'.
else: a. string print
"\n" print.

View file

@ -0,0 +1,20 @@
is-positive = _ > 0 # equivalent to lam(x): x > 0 end
fun fizzbuzz(n :: Number%(is-positive)) -> String:
doc: ```For positive input which is multiples of three return 'Fizz', for the multiples of five return 'Buzz'.
For numbers which are multiples of both three and five return 'FizzBuzz'. Otherwise, return the number itself.```
ask:
| num-modulo(n, 15) == 0 then: "FizzBuzz"
| num-modulo(n, 3) == 0 then: "Fizz"
| num-modulo(n, 5) == 0 then: "Buzz"
| otherwise: num-to-string(n)
end
where:
fizzbuzz(1) is "1"
fizzbuzz(101) is "101"
fizzbuzz(45) is "FizzBuzz"
fizzbuzz(33) is "Fizz"
fizzbuzz(25) is "Buzz"
end
range(1, 101).map(fizzbuzz).each(print)

View file

@ -0,0 +1,6 @@
for n = 1 to 100
if n % 15 = 0 see "" + n + " = " + "FizzBuzz"+ nl
but n % 5 = 0 see "" + n + " = " + "Buzz" + nl
but n % 3 = 0 see "" + n + " = " + "Fizz" + nl
else see "" + n + " = " + n + nl ok
next

View file

@ -0,0 +1,16 @@
import <Utilities/Conversion.sl>;
import <Utilities/Sequence.sl>;
main(args(2)) :=
let
result[i] :=
"FizzBuzz" when i mod 3 = 0 and i mod 5 = 0
else
"Fizz" when i mod 3 = 0
else
"Buzz" when i mod 5 = 0
else
intToString(i)
foreach i within 1 ... 100;
in
delimit(result, '\n');

View file

@ -0,0 +1,14 @@
(define fizzbuzz
101 -> (nl)
N -> (let divisible-by? (/. A B (integer? (/ A B)))
(cases (divisible-by? N 15) (do (output "Fizzbuzz!~%")
(fizzbuzz (+ N 1)))
(divisible-by? N 3) (do (output "Fizz!~%")
(fizzbuzz (+ N 1)))
(divisible-by? N 5) (do (output "Buzz!~%")
(fizzbuzz (+ N 1)))
true (do (output (str N))
(nl)
(fizzbuzz (+ N 1))))))
(fizzbuzz 1)

View file

@ -0,0 +1,9 @@
{ |i|
if (i %% 3) {
print "Fizz"
i %% 5 && print "Buzz"
print "\n"
}
elsif (i %% 5) { say "Buzz" }
else { say i }
} * 100

View file

@ -0,0 +1,6 @@
func fizzbuzz({ _ %% 15 }) { "FizzBuzz" }
func fizzbuzz({ _ %% 5 }) { "Buzz" }
func fizzbuzz({ _ %% 3 }) { "Fizz" }
func fizzbuzz( n ) { n }
for n in (1..100) { say fizzbuzz(n) }

View file

@ -0,0 +1 @@
{|i|say "#{<Fizz>[i%3]}#{<Buzz>[i%5]}"||i}*100

View file

@ -0,0 +1,8 @@
1.to 100
[
println(
if idx.mod(15) = 0 ["FizzBuzz"]
idx.mod(3) = 0 ["Fizz"]
idx.mod(5) = 0 ["Buzz"]
else [idx])
]

View file

@ -0,0 +1,7 @@
1.to 100
[
!str: ""
if idx.mod(3) = 0 [str += "Fizz"]
if idx.mod(5) = 0 [str += "Buzz"]
println(if str.empty? [idx] else [str])
]

View file

@ -0,0 +1,6 @@
1.to 100
[
!str: if idx.mod(3) = 0 ["Fizz"] else [""]
if idx.mod(5) = 0 [str += "Buzz"]
println(if str.empty? [idx] else [str])
]

View file

@ -0,0 +1,12 @@
for i in 1...100 {
switch (i % 3, i % 5) {
case (0, 0):
print("FizzBuzz")
case (0, _):
print("Fizz")
case (_, 0):
print("Buzz")
default:
print(i)
}
}

View file

@ -0,0 +1,22 @@
| FizzBuzz
1 I
if I LE 100
mod I 3 X
mod I 5 Y
if X EQ 0
'FIZZ' $S
if Y EQ 0
+ 'BUZZ' $S
endif
else
if Y EQ 0
'BUZZ' $S
else
~ I $S
endif
endif
$S []
+ I
goif
endif

View file

@ -0,0 +1,16 @@
#
# fizzbuzz
#
decl int i
for (set i 1) (< i 101) (inc i)
if (= (mod i 3) 0)
out "fizz" console
end if
if (= (mod i 5) 0)
out "buzz" console
end if
if (not (or (= (mod i 3) 0) (= (mod i 5) 0)))
out i console
end if
out endl console
end for

View file

@ -0,0 +1,9 @@
for i 1 (i <= 100) ++i
prn (if (divides i 15)
"FizzBuzz"
(divides i 3)
"Fizz"
(divides i 5)
"Buzz"
:else
i)

View file

@ -0,0 +1 @@
@each &x!console.log x !*&x?{%%x 15 "FizzBuzz" %%x 5 "Buzz" %%x 3 "Fizz" x} @to 100

View file

@ -0,0 +1,13 @@
(defun fizzbuzz ()
(defun fizzb (x y)
(display (cond
((= (mod x 3) (mod x 5) 0) "FizzBuzz")
((= (mod x 3) 0) "Fizz")
((= (mod x 5) 0) "Buzz")
(t x)))
(newline)
(if (< x y)
(fizzb (+ x 1) y)))
(fizzb 1 100))
(fizzbuzz)

View file

@ -0,0 +1,2 @@
for $n in 1 to 100 return
concat('fizz'[not($n mod 3)], 'buzz'[not($n mod 5)], $n[$n mod 15 = (1,2,4,7,8,11,13,14)])

View file

@ -0,0 +1,2 @@
for $n in 1 to 100 return
($n, 'Fizz', 'Buzz', 'FizzBuzz')[number(($n mod 3) = 0) + number(($n mod 5) = 0)*2 + 1]

View file

@ -0,0 +1,6 @@
range(1;101)
| if . % 15 == 0 then "FizzBuzz"
elif . % 5 == 0 then "Buzz"
elif . % 3 == 0 then "Fizz"
else .
end

View file

@ -0,0 +1,4 @@
range(100) + 1 | [(
(select(. % 3 == 0) | "Fizz"),
(select(. % 5 == 0) | "Buzz")
) // tostring] | join("")