FizzBuzz: Difference between revisions

11,984 bytes added ,  22 days ago
m (→‎{{header|Sidef}}: shorter one-liner)
 
(44 intermediate revisions by 30 users not shown)
Line 9:
 
But:
:*   for multiples of three,   print   '''Fizz'''     (instead of the number);
:*   for multiples of five,   print   '''Buzz'''     (instead of the number);
:*   for multiples of both three and five,   print   '''FizzBuzz'''     (instead of the number) .
 
 
Line 202:
fb = |{ fizz }{ buzz }| in
( switch #( fb when space then i else fb ) ) ) ).</syntaxhighlight>
 
=={{header|ABC}}==
<syntaxhighlight lang="ABC">HOW TO RETURN fizzbuzz num:
PUT "" IN result
PUT {[3]: "Fizz"; [5]: "Buzz"} IN divwords
FOR div IN keys divwords:
IF num mod div=0:
PUT result^divwords[div] IN result
IF result="":
PUT num>>0 IN result
RETURN result
 
FOR i IN {1..100}:
WRITE fizzbuzz i/</syntaxhighlight>
 
=={{header|ACL2}}==
Line 491 ⟶ 505:
[38] ⍝ 1 2 Fizz 4 Buzz Fizz 7 8 Fizz Buzz 11 Fizz 13 14 FizzBuzz
∇</syntaxhighlight>
 
I prefer the DRYness of solutions that don't have "FizzBuzz" as a separate case; here's such a solution that works with both Dyalog and GNU. You may want to prepend `⍬⊣` to the whole thing in GNU to keep it from returning the list as the value of the expression, causing the interpreter to print it out a second time.
 
{{works with|Dyalog APL}}
{{works with|GNU APL}}
<syntaxhighlight lang="apl">⎕io←1
{⎕←∊'Fizz' 'Buzz'⍵/⍨d,⍱/d←0=3 5|⍵}¨⍳100</syntaxhighlight>
 
Explanation:
<pre>
⎕io←1 Set the index origin to 1; if it were set to 0, the next
step would count from 0 to 99 instead of 1 to 100.
 
{ }¨⍳100 Do the thing in braces for each integer from 1 through 100.
 
3 5|⍵ Make a list of the remainders when the current number is
divided by 3 and 5.
 
d←0= Make it a Boolean vector: true for remainder=0, false
otherwise. Name it d.
 
d,⍱/ Prepend d to the result of reducing itself with XNOR,
yielding a three-element Boolean vector. The first element
is true if the number is divisible by 3; the second if it's
divisible by 5; and the third only if it's divisible by
neither.
 
'Fizz' 'Buzz'⍵/⍨ Use the Boolean vector as a mask to select elements from
a new triple consisting of 'Fizz', 'Buzz', and the current
number. Each of the three elements will be included in the
selection only if the corresponding Boolean is true.
 
∊ Combine the selected elements into one vector/string
 
⎕← And print it out.</pre>
 
=={{header|AppleScript}}==
Line 1,102 ⟶ 1,151:
 
100 times }</syntaxhighlight>
 
=={{header|BabyCobol}}==
<syntaxhighlight lang="cobol">
* NB: ANY does not exist in BabyCobol so the elegant
* EVALUATE-based COBOL-style solution is impossible here.
* Note the subtly unbalanced IF/ENDs yet valid END at the end.
IDENTIFICATION DIVISION.
PROGRAM-ID. FIZZBUZZ.
DATA DIVISION.
01 INT PICTURE IS 9(3).
01 REM LIKE INT.
01 TMP LIKE INT.
PROCEDURE DIVISION.
LOOP VARYING INT TO 100
DIVIDE 3 INTO INT GIVING TMP REMAINDER REM
IF REM = 0
THEN DISPLAY "Fizz" WITH NO ADVANCING
DIVIDE 5 INTO INT GIVING TMP REMAINDER REM
IF REM = 0
THEN DISPLAY "Buzz" WITH NO ADVANCING
DIVIDE 15 INTO INT GIVING TMP REMAINDER REM
IF REM = 0
THEN DISPLAY ""
ELSE DISPLAY INT
END.
</syntaxhighlight>
 
=={{header|BaCon}}==
Line 1,319 ⟶ 1,394:
Using the Catch modifier for flow control
<syntaxhighlight lang="bqn">((∾´"fizz"‿"buzz"/˜0=3‿5|⊢)⎊⊢)¨1+↕100</syntaxhighlight>
 
Using the Choose Combonator with a rank 2 array
<syntaxhighlight lang="bqn">(3‿5 (0=|)◶[⊢‿"fizz","buzz"‿"fizzbuzz"] ⊢)¨ 1+↕100</syntaxhighlight>
 
=={{header|Bracmat}}==
Line 1,366 ⟶ 1,444:
? str
END FOR</syntaxhighlight>
 
=={{header|Bruijn}}==
<syntaxhighlight lang="bruijn">
:import std/Combinator .
:import std/String .
:import std/Number .
 
main [y [[0 =? (+101) case-end case-rec]] (+1)]
case-rec str ++ "\n" ++ (1 ++0)
str fizzbuzz "FizzBuzz" (fizz "Fizz" (buzz "Buzz" (number→string 0)))
fizz =?(0 % (+3))
buzz =?(0 % (+5))
fizzbuzz fizz buzz fizz
case-end empty
</syntaxhighlight>
 
=={{header|C}}==
Line 2,688 ⟶ 2,781:
 
(fizzbuzz 100)</syntaxhighlight>
 
Solution 8:
<syntaxhighlight lang="lisp">(defun range (min max)
(loop
:for x :from min :to max
:collect x))
 
(defun fizzbuzz ()
(map 'nil #'(lambda (n)
(princ
(cond
((zerop (mod n 15)) "FizzBuzz!")
((zerop (mod n 5)) "Buzz!")
((zerop (mod n 3)) "Fizz!")
(t n))
(terpri)))
(range 1 100)))</syntaxhighlight>
 
First 16 lines of output:
<pre>
Line 2,827 ⟶ 2,938:
Eval compute in fizz_buzz.
</syntaxhighlight>
 
Output
 
<pre>
= "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
Fizz
64
Buzz
Fizz
67
68
Fizz
Buzz
71
Fizz
73
74
FizzBuzz
76
77
Fizz
79
Buzz
Fizz
82
83
Fizz
Buzz
86
Fizz
88
89
FizzBuzz
91
92
Fizz
94
Buzz
Fizz
97
98
Fizz
Buzz"%string
: string
</pre>
 
=={{header|Cowgol}}==
Line 3,688 ⟶ 3,905:
(dotimes (i 101)
(message "%s" (fizzbuzz i)))</syntaxhighlight>
 
=={{header|EMal}}==
<syntaxhighlight lang="emal">
logic isFizz, isBuzz
for int count = 1; count <= 100; ++count
isFizz = count % 3 == 0
isBuzz = count % 5 == 0
if isFizz and isBuzz do writeLine("Fizz Buzz")
else if isFizz do writeLine("Fizz")
else if isBuzz do writeLine("Buzz")
else do writeLine(count)
end
end
</syntaxhighlight>
 
=={{header|Emojicode}}==
Line 3,833 ⟶ 4,064:
=={{header|Euler}}==
The original Euler implementations did not allow "long" strings, hence the use of a list here to print FizzBuzz.
'''begin''' '''new''' i; '''label''' iLoop;
<syntaxhighlight lang="euler">
begin new i; label&lt;- iLoop0;
iLoop: '''if''' [ i &lt;- i + 1 ] &lt;= 100 '''then''' '''begin'''
i <- 0;
'''out''' '''if''' i '''mod''' 15 = 0 '''then''' ( "Fizz", "Buzz" )
iLoop: if [ i <- i + 1 ] <= 100 then begin
out if '''else''' '''if''' i '''mod''' 15 5 = 0 '''then ( "Fizz",''' "Buzz" )
'''else''' '''if''' i '''mod''' 53 = 0 '''then''' "BuzzFizz"
'''else if''' i mod 3 = 0 then "Fizz";
'''goto''' else i;iLoop
'''end''' '''else''' goto iLoop0
'''end''' $
end else 0
end $
</syntaxhighlight>
 
=={{header|Euphoria}}==
Line 3,946 ⟶ 4,175:
 
MAIN: FizzBuzzQuxx-100
</syntaxhighlight>
 
Another approach is leverage Factor's [https://docs.factorcode.org/content/article-predicates.html predicate] and [https://docs.factorcode.org/content/article-intersections.html intersection] classes.
<syntaxhighlight lang="factor">
USING: io kernel math math.functions math.parser ranges
sequences ;
IN: rosetta-code.fizz-buzz
 
PREDICATE: fizz < integer 3 divisor? ;
PREDICATE: buzz < integer 5 divisor? ;
 
INTERSECTION: fizzbuzz fizz buzz ;
 
GENERIC: fizzbuzz>string ( n -- str )
 
M: fizz fizzbuzz>string
drop "Fizz" ;
 
M: buzz fizzbuzz>string
drop "Buzz" ;
 
M: fizzbuzz fizzbuzz>string
drop "FizzBuzz" ;
 
M: integer fizzbuzz>string
number>string ;
 
MAIN: [ 1 100 [a..b] [ fizzbuzz>string print ] each ]
</syntaxhighlight>
 
Line 4,342 ⟶ 4,599:
 
{{FormulaeEntry|page=https://formulae.org/?script=examples/FizzBuzz}}
 
'''Solution'''
 
[[File:Fōrmulæ - FizzBuzz 01.png]]
 
[[File:Fōrmulæ - FizzBuzz 01a.png]]
 
[[File:Fōrmulæ - FizzBuzz 02.png]]
 
=={{header|Gambas}}==
Line 5,042 ⟶ 5,307:
When play begins: count. Use no scoring.</syntaxhighlight>
 
=={{header|Insitux}}==
<syntaxhighlight lang="insitux">(function fizzbuzz n
(match (map (rem n) [3 5])
[0 0] "FizzBuzz"
[0 _] "Fizz"
[_ 0] "Buzz"
n))
 
(loop 100 i
(-> i inc fizzbuzz print))</syntaxhighlight>
 
=={{header|Io}}==
Line 5,872 ⟶ 6,148:
=={{header|langur}}==
<syntaxhighlight lang="langur">for .i of 100 {
writeln givenswitch(0; .i rem 15: "FizzBuzz"; .i rem 5: "Buzz"; .i rem 3: "Fizz"; .i)
}</syntaxhighlight>
 
{{works with|langur|0.8.1}}
<syntaxhighlight lang="langur">for .i of 100 {
writeln if(.i div 15: "FizzBuzz"; .i div 5: "Buzz"; .i div 3: "Fizz"; .i)
Line 5,907 ⟶ 6,182:
\fizzBuzz{101}
\end{document}</syntaxhighlight>
 
=={{header|LDPL}}==
<syntaxhighlight lang="ldpl">data:
i is number
n is number
 
procedure:
for i from 1 to 101 step 1 do
modulo i by 15 in n
if n is equal to 0 then
display "FizzBuzz" lf
continue
end if
modulo i by 5 in n
if n is equal to 0 then
display "Buzz" lf
continue
end if
modulo i by 3 in n
if n is equal to 0 then
display "Fizz" lf
continue
end if
display i lf
repeat
</syntaxhighlight>
 
=={{header|Lean}}==
Line 6,202 ⟶ 6,503:
print(t[i%15] or i)
end</syntaxhighlight>
 
=== Metatable insertion ===
Sets any numeric key to its fizzbuzz value so that fizzbuzz[30] is "fizzbuzz"
<syntaxhighlight lang="lua">local mt = {
__newindex = (function (t, k, v)
if type(k) ~= "number" then rawset(t, k, v)
elseif 0 == (k % 15) then rawset(t, k, "fizzbuzz")
elseif 0 == (k % 5) then rawset(t, k, "fizz")
elseif 0 == (k % 3) then rawset(t, k, "buzz")
else rawset(t, k, k) end
return t[k]
end)
}
 
local fizzbuzz = {}
setmetatable(fizzbuzz, mt)
 
for i=1,100 do fizzbuzz[i] = i end
for i=1,100 do print(fizzbuzz[i]) end
</syntaxhighlight>
 
=== Fast Version without Modulo ===
Line 6,429 ⟶ 6,750:
Another one-liner using Map (the /@ operator shorthand of it) and a pure function with a very readable Which
<syntaxhighlight lang="mathematica"> Which[ Mod[#,15] == 0, "FizzBuzz", Mod[#, 3] == 0, "Fizz", Mod[#,5]==0, "Buzz", True, #]& /@ Range[1,100] </syntaxhighlight>
 
Additional examples using DownValue pattern matching, the first without Mod'ing 15:
<syntaxhighlight lang="mathematica">f[n_] := f[n, Mod[n, {3, 5}]]
f[_, {0, 0}] := "FizzBuzz"
f[_, {0, _}] := "Fizz"
f[_, {_, 0}] := "Buzz"
f[n_, {_, _}] := n
 
f /@ Range[100]</syntaxhighlight>
 
<syntaxhighlight lang="mathematica">f[n_] := f[n, Mod[n, 15]]
f[_, 0] := "FizzBuzz"
 
f[n_, _] := f[n, Mod[n, {3, 5}]]
f[_, {0, _}] := "Fizz"
f[_, {_, 0}] := "Buzz"
f[n_, {_, _}] := n
 
f /@ Range[100]</syntaxhighlight>
 
=={{header|MATLAB}}==
Line 6,464 ⟶ 6,804:
end
end</syntaxhighlight>
 
'''straightforward'''
<syntaxhighlight lang="matlab">
x = string(1:100);
x(3:3:$) = 'Fizz';
x(5:5:$) = 'Buzz';
x(3*5:3*5:$) = 'FizzBuzz'
</syntaxhighlight>
 
=={{header|Maxima}}==
Line 7,194 ⟶ 7,542:
in
fizzbuzz { }</syntaxhighlight>
 
=={{header|Nu}}==
<syntaxhighlight lang="nu">
(1..100
| each {|i| $"(if $i mod 3 == 0 {"Fizz"})(if $i mod 5 == 0 {"Buzz"})"
| if ($in == "") {$i} else {$in}}
| str join "\n")
</syntaxhighlight>
 
=={{header|Oberon-2}}==
Line 7,321 ⟶ 7,677:
(iota 100))
</syntaxhighlight>
 
=={{header|Onyx (wasm)}}==
<syntaxhighlight lang="C">
use core { * }
 
fizzbuzz :: (len: u32) -> void {
for i in 1..len+1 {
msg : str;
if (i%3 == 0 && i%5 == 0) { msg = "FizzBuzz !!!"; }
elseif (i%3 == 0) { msg = "Fizz"; }
elseif (i%5 == 0) { msg = "Buzz"; }
else { msg = tprintf("{}", i); }
printf("{}\n", msg);
}
}
 
main :: () {
fizzbuzz(100);
}
</syntaxhighlight>
 
=={{header|OOC}}==
<syntaxhighlight lang="ooc">fizz: func (n: Int) -> Bool {
Line 8,358 ⟶ 8,735:
Wait for the escape key.
Shut down.
</syntaxhighlight>
 
=={{header|Pointless}}==
<syntaxhighlight lang="pointless">
output =
range(1, 100)
|> map(fizzBuzz)
|> printLines
 
fizzBuzz(n) =
if result == "" then n else result
where result = fizzBuzzString(n)
 
fizzBuzzString(n) =
(if n % 3 == 0 then "Fizz" else "")
+ (if n % 5 == 0 then "Buzz" else "")
</syntaxhighlight>
 
Line 8,795 ⟶ 9,188:
=={{header|Python}}==
===Python2: Simple===
<syntaxhighlight lang="python">for i in xrangerange(1, 101):
if i % 15 == 0:
print "FizzBuzz"
Line 8,926 ⟶ 9,319:
</syntaxhighlight>
 
=={{header|Qq}}==
 
q is the query language for '''kdb+'''.
 
<syntaxhighlight lang="q">
{(2 sv not x mod/:5 3)'[;`fizz;`buzz;`fizzbuzz]`$string x}</syntaxhighlight>
 
 
Usage:
<syntaxhighlight lang="q">
q)/ Fizzbuzz
q){(sum 1 2*0=x mod/:3 5)'[`$string x;`fizz;`buzz;`fizzbuzz]}1+til 20
q)fb:{(2 sv not x mod/:5 3)'[;`fizz;`buzz;`fizzbuzz]`$string x}
q)fb 1+til 20
`1`2`fizz`4`buzz`fizz`7`8`fizz`buzz`11`fizz`13`14`fizzbuzz`16`17`fizz`19`buzz</syntaxhighlight>
 
https://code.kx.com/q/learn/reading/fizzbuzz/<br>
https://code.kx.com/q/ref/sv/<br>
https://code.kx.com/q/ref/maps/#case
 
Explanation:
<syntaxhighlight lang="q">
q)show x:1+til 20
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
q)x mod/:5 3
1 2 3 4 0 1 2 3 4 0 1 2 3 4 0 1 2 3 4 0
1 2 0 1 2 0 1 2 0 1 2 0 1 2 0 1 2 0 1 2
q)not x mod/:5 3
00001000010000100001b
00100100100100100100b
q)show i:2 sv not x mod/:5 3 / binary decode
0 0 1 0 2 1 0 0 1 2 0 1 0 0 3 0 0 1 0 2
q)(`$string x;`fizz;`buzz;`fizzbuzz)
`1`2`3`4`5`6`7`8`9`10`11`12`13`14`15`16`17`18`19`20
`fizz
`buzz
`fizzbuzz
q)i'[`$string x;`fizz;`buzz;`fizzbuzz] / Case iterator
`1`2`fizz`4`buzz`fizz`7`8`fizz`buzz`11`fizz`13`14`fizzbuzz`16`17`fizz`19`buzz</syntaxhighlight>
 
=={{header|QB64}}==
Line 8,948 ⟶ 9,372:
 
=={{header|Quackery}}==
<syntaxhighlight lang="quackery"> [100 times
[ i^ 1+ true
over 3 'mod not echo
overif 3[ modsay 0"fizz" =drop iffalse ]
over 5 mod not [ say "Fizz"
if [ say "buzz" drop ' dropfalse ]
iff echo overelse 5drop mod 0 = if
sp ] [ say "Buzz"
</syntaxhighlight>
drop ' drop ]
do
sp ]
cr ] is fizzbuzz ( n --> )
 
say 'First 100 turns in the game of fizzbuzz:' cr cr
100 fizzbuzz cr</syntaxhighlight>
 
 
=={{header|R}}==
Line 9,137 ⟶ 9,554:
]
]</syntaxhighlight>
 
=={{header|Refal}}==
<syntaxhighlight lang="refal">$ENTRY Go {
= <FizzBuzz 1>;
};
 
FizzBuzz {
101 = ;
s.N = <Prout <Item s.N>>
<FizzBuzz <+ 1 s.N>>;
};
 
Item {
s.N, <Mod s.N 15>: 0 = FizzBuzz;
s.N, <Mod s.N 5>: 0 = Buzz;
s.N, <Mod s.N 3>: 0 = Fizz;
s.N = s.N;
};</syntaxhighlight>
 
=={{header|Retro}}==
Line 9,421 ⟶ 9,856:
Whisper my world
 
=={{header|RPG}}==
<nowiki>**</nowiki>free
dcl-s ix Int(5);
for ix = 1 to 100;
select;
when %rem(ix:15) = 0;
dsply 'FizzBuzz';
when %rem(ix:5) = 0;
dsply 'Buzz';
when %rem(ix:3) = 0;
dsply 'Fizz';
other;
dsply (%char(ix));
endsl;
endfor;
 
=={{header|RPL}}==
Line 10,046 ⟶ 10,497:
put output
end repeat</syntaxhighlight>
 
=={{header|SETL}}==
<syntaxhighlight lang="setl">program fizzbuzz;
loop for n in [1..100] do
print(fizzbuzz(n));
end loop;
 
proc fizzbuzz(n);
divs := [[3, "Fizz"], [5, "Buzz"]];
return +/[w : [d,w] in divs | n mod d=0] ? str n;
end proc;
end program;</syntaxhighlight>
 
=={{header|SequenceL}}==
Line 10,133 ⟶ 10,596:
=={{header|Sidef}}==
Structured:
<syntaxhighlight lang="rubyperl">{ |i|
if (i %% 3) {
print "Fizz"
Line 10,141 ⟶ 10,604:
elsif (i %% 5) { say "Buzz" }
else { say i }
} *<< 1..100</syntaxhighlight>
 
Declarative:
<syntaxhighlight lang="rubyperl">func fizzbuzz({ _ %% 15 }) { "FizzBuzz" }
func fizzbuzz({ _ %% 5 }) { "Buzz" }
func fizzbuzz({ _ %% 3 }) { "Fizz" }
Line 10,489 ⟶ 10,952:
print(s ?? i)
}</syntaxhighlight>
 
=== using a precomputed cycle ===
<syntaxhighlight lang="swift">
import Foundation
 
let formats: [String] = [
"%d",
"%d",
"fizz",
"%d",
"buzz",
"fizz",
"%d",
"%d",
"fizz",
"buzz",
"%d",
"fizz",
"%d",
"%d",
"fizzbuzz",
]
 
var count = 0
var index = 0
while count < 100 {
count += 1
print(String(format: formats[index], count))
index += 1
index %= 15
}
</syntaxhighlight>
 
=={{header|Symsyn}}==
Line 10,677 ⟶ 11,172:
See [[FizzBuzz/Assembly]]
 
=={{header|TI-99/4a TI BASIC / Extended BASIC}}==
See [[FizzBuzz/AssemblyBasic]]
 
=={{Header|Tiny BASIC}}==
Line 10,817 ⟶ 11,312:
@ n += 1
end</syntaxhighlight>
 
=={{header|Uiua}}==
<syntaxhighlight lang="Uiua">
⟨⟨⟨&p|&p"Fizz"◌⟩=0◿3.|&p"Buzz"◌⟩=0◿5.|&p"Fizzbuzz"◌⟩=0◿15.+1⇡100
</syntaxhighlight>
 
=={{header|Ursa}}==
Line 11,364 ⟶ 11,864:
 
=={{header|Wren}}==
<syntaxhighlight lang="ecmascriptwren">for (i in 1..100) {
if (i % 15 == 0) {
System.print("FizzBuzz")
Line 11,802 ⟶ 12,302:
 
<syntaxhighlight lang="yaml">
#!/usr/bin/env ys-0
map(say):
map:
- fn (x):
s =:
str:
- (zero? mod(x 3)) ?: "Fizz"
- (zero? mod(x 5)) ?: "Buzz"
if (empty? s): x, s
- (1 .. 100)
</syntaxhighlight>
 
# This program has multiple implementations of "fizzbuzz".
<syntaxhighlight lang="yaml">
 
map(say):
# usage: yamlscript fizzbuzz.ys [<count>] [<fizzbuzz-fn-#>]
 
# The main function runs a certain requested fizzbuzz implementation function
# for a certain requested number (default is 100).
 
defn main(count=100 impl=1):
fizzbuzz =: "fizzbuzz-$impl"
 
when-not ENV.'YS_TEST':
say: "Running function '$fizzbuzz' with count=$count"
 
function =: resolve(fizzbuzz.symbol())
result =: function(count)
 
mapv say: result
 
 
# These implementation functions were adapted from
# https://rosettacode.org/wiki/FizzBuzz#Clojure
 
defn fizzbuzz-1(n):
map:
- fn fn(x):
???cond:
zero?(mod(x % 15)) : "'FizzBuzz"'
zero?(mod(x % 5)): : "'Buzz"'
zero?(mod(x % 3)): : "'Fizz"'
:else=>: x
- ( =>: 1 .. 100)n
</syntaxhighlight>
 
defn fizzbuzz-2(n):
<syntaxhighlight lang="yaml">
map(say):
loop [i 1, l []]:
if (i > 100n):
- =>: l
- ^^^ recur inc(i):
- inc(i) conj l:
- conj cond:
- l zero?(i % 15): 'FizzBuzz'
- zero???(i % 5): 'Buzz'
zero?(mod(i 15))% 3): "FizzBuzz" 'Fizz'
zero?(mod(i 5)) =>: "Buzz"i
 
zero?(mod(i 3)) : "Fizz"
defn fizzbuzz-3(n):
:else: i
map:
fn(x):
s =:
str:
when zero?(x % 3): 'Fizz'
=>: (zero?(x % 5) && 'Buzz') || nil
if empty?(s): x s
rng: 1 n
</syntaxhighlight>
{{out}}
<pre>
$ ys sample/fizzbuzz.ys 16 2
Running function 'fizzbuzz-2' with count=16
1
2
Fizz
4
Buzz
Fizz
7
8
Fizz
Buzz
11
Fizz
13
14
FizzBuzz
16
</pre>
 
=={{header|Yorick}}==
1

edit