FizzBuzz: Difference between revisions

20,801 bytes added ,  1 month ago
m (Update lang example: Improve control flow statements)
(73 intermediate revisions by 40 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 280 ⟶ 294:
end loop;
end Fizzbuzz;</syntaxhighlight>
 
 
=={{header|Agda}}==
<syntaxhighlight lang="agda">
module FizzBuzz where
 
open import Agda.Builtin.IO using (IO)
 
open import Agda.Builtin.Unit renaming (⊤ to Unit)
 
open import Data.Bool using (Bool ; false ; true ; if_then_else_)
 
open import Data.Nat using (ℕ ; zero ; suc ; _≡ᵇ_ ; _%_)
 
open import Data.Nat.Show using (show)
 
open import Data.List using (List ; [] ; _∷_ ; map)
 
open import Data.String using (String ; _++_ ; unlines)
 
postulate putStrLn : String -> IO Unit
{-# FOREIGN GHC import qualified Data.Text as T #-}
{-# COMPILE GHC putStrLn = putStrLn . T.unpack #-}
 
fizz : String
fizz = "Fizz"
 
buzz : String
buzz = "Buzz"
 
_isDivisibleBy_ : (n : ℕ) -> (m : ℕ) -> Bool
n isDivisibleBy zero = false
n isDivisibleBy (suc k) = ((n % (suc k)) ≡ᵇ 0)
 
getTerm : (n : ℕ) -> String
getTerm n =
if (n isDivisibleBy 15) then (fizz ++ buzz)
else if (n isDivisibleBy 3) then fizz
else if (n isDivisibleBy 5) then buzz
else (show n)
 
range : (a : ℕ) -> (b : ℕ) -> List (ℕ)
range k zero = []
range k (suc m) = k ∷ (range (suc k) m)
 
getTerms : (n : ℕ) -> List (String)
getTerms n = map getTerm (range 1 n)
 
fizzBuzz : String
fizzBuzz = unlines (getTerms 100)
 
main : IO Unit
main = putStrLn fizzBuzz
</syntaxhighlight>
 
=={{header|ALGOL 68}}==
Line 437 ⟶ 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,048 ⟶ 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,265 ⟶ 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,312 ⟶ 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,093 ⟶ 2,240:
=={{header|Chef}}==
See [[FizzBuzz/EsoLang]]
 
=={{header|Cherrycake}}==
<syntaxhighlight lang="cherrycake">
# Route with custom number of iterations
cached get ~/:n {
 
# Get the Number of Iterations from the URL Params
int n = req.params.n || 100
 
# Loop through each iteration
for (i in range(n)) {
 
if (i % 2 == 0 && i % 3 == 0) { res.write("FizzBuzz\n") continue }
if (i % 2 == 0) { res.write("Fizz\n"); continue; }
if (i % 3 == 0) { res.write("Buzz\n"); continue; }
res.write(i + "\n");
 
}
 
# Close the connection
res.end();
 
}
</syntaxhighlight>
 
=={{header|Clay}}==
Line 2,610 ⟶ 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,697 ⟶ 2,886:
(** Definition of [string_of_nat] to convert natural numbers to strings. *)
 
Definition ascii_of_digit (n : nat) : ascii :=
ascii_of_nat (n + 48).
 
Definition is_digit (n : nat) : bool :=
andb (0 <=? n) (n <=? 9).
 
Fixpoint rec_string_of_nat (counter : nat) (n : nat) (acc : string) : string :=
match counter with
| 0 => EmptyString
| S c =>
if (is_digit n)
then String (ascii_of_digit n) acc
Line 2,713 ⟶ 2,902:
(** The counter is only used to ensure termination. *)
 
Definition string_of_nat (n : nat) : string :=
rec_string_of_nat n n EmptyString.
 
Line 2,719 ⟶ 2,908:
(** The FizzBuzz problem. *)
 
Definition fizz : string :=
"Fizz" .
 
Definition buzz : string :=
"Buzz" .
 
Definition new_line : string :=
String (ascii_of_nat 10) EmptyString.
 
Definition is_divisible_by (n : nat) (k : nat) : bool :=
(n mod k) =? 0.
 
Definition get_fizz_buzz_termget_term (n : nat) : string :=
if (is_divisible_by n 15) then fizz ++ buzz
else if (is_divisible_by n 3) then fizz
Line 2,737 ⟶ 2,926:
else (string_of_nat n).
 
Definition get_first_positive_numbersrange (na : nat) (b : nat) : list nat :=
seq 1a nb.
 
Definition fizz_buzz_termsget_terms (n : nat) : list string :=
map get_fizz_buzz_termget_term (get_first_positive_numbersrange 1 n).
 
Definition fizz_buzz : string :=
concat new_line (fizz_buzz_termsget_terms 100).
 
(** This shows the string. *)
Line 2,750 ⟶ 2,939:
</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,301 ⟶ 3,595:
 
=={{header|Ecstasy}}==
<syntaxhighlight lang="java">module FizzBuzz
module FizzBuzz {
{
void run() {
{
@Inject Console console;
for (Int x : 1..100) {
console.print(switch (x % 3, x % 5) {
console.print(switch (x % 3, x % 5)
{
case (0, 0): "FizzBuzz";
case (0, _): "Fizz";
case (_, 0): "Buzz";
case (_, _): x.toString();
});
}
}
}</syntaxhighlight>
}
</syntaxhighlight>
 
=={{header|Eero}}==
Line 3,613 ⟶ 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,648 ⟶ 3,954:
🍉
🍉</syntaxhighlight>
 
=={{header|Enguage}}==
<syntaxhighlight lang="Enguage">FizzBuzz</syntaxhighlight>
 
This source code is supposed to look like plain old English but is, in fact, executable. When used in an Android app, it gives the user direct access to computational abilities of your phone.
 
It is taken from [https://bitbucket.org/martinwheatman/enguage/src/develop/etc/dict/f/fizzbuzz.entry the dictionary entry for fizzbuzz]
 
This shows the interpretation of two utterances, the latter of which are called recursively. Enguage is not very efficient, but that's not its goal!
 
NB. Any line beginning with a '#' is a comment, like Unix shells, but any comment following the ']' character are unit tests exercising this code.
 
<pre>
On "what is the fizzbuzz of N":
is N divisible by 5 and 3;
if so, reply "fizzbuzz";
is N divisible by 5;
if so, reply "buzz";
is N divisible by 3;
if so, reply "fizz";
reply "N".
On "do fizzbuzz between N and LIMIT":
what is the fizzbuzz of N;
remember this;
set next to the evaluation of N + 1;
NEXT is equal to LIMIT;
if so, what is the fizzbuzz of LIMIT;
if not, do fizzbuzz between NEXT and LIMIT.
#] what is the fizzbuzz of 1: 1.
#] what is the fizzbuzz of 12: fizz.
#] what is the fizzbuzz of 25: buzz.
#] what is the fizzbuzz of 75: fizzbuzz.
 
#] set limit to 5.
#] do fizzbuzz between 1 and LIMIT.
</pre>
 
On downloading this repo, if git and make are installed, this unit test can be run with:
<pre>
$ git clone https://github.com/martinwheatman/enguage.git
$ cd enguage
$ make jar
$ export PATH=$PATH:./sbin
$ java -jar lib/enguage.jar -T fizzbuzz
</pre>
 
Output:
<pre>
TEST: fizzbuzz
==============
 
user> what is the fizzbuzz of 1.
enguage> 1.
 
user> what is the fizzbuzz of 12.
enguage> fizz.
 
user> what is the fizzbuzz of 25.
enguage> buzz.
 
user> what is the fizzbuzz of 75.
enguage> fizzbuzz.
 
user> set limit to 5.
enguage> ok , limit is set to 5.
 
user> do fizzbuzz between 1 and LIMIT.
enguage> 1 . 2 . fizz . 4 . buzz.
1 test group(s) found
+++ PASSED 6 tests in 442ms +++
</pre>
 
=={{header|Erlang}}==
Line 3,682 ⟶ 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,795 ⟶ 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,190 ⟶ 4,598:
=={{header|Fōrmulæ}}==
 
{{FormulaeEntry|page=https://formulae.org/?script=examples/FizzBuzz}}
Fōrmulæ programs are not textual, visualization/edition of programs is done showing/manipulating structures but not text. Moreover, there can be multiple visual representations of the same program. Even though it is possible to have textual representation &mdash;i.e. XML, JSON&mdash; they are intended for storage and transfer purposes more than visualization and edition.
 
'''Solution'''
Programs in Fōrmulæ are created/edited online in its [https://formulae.org website], However they run on execution servers. By default remote servers are used, but they are limited in memory and processing power, since they are intended for demonstration and casual use. A local server can be downloaded and installed, it has no limitations (it runs in your own computer). Because of that, example programs can be fully visualized and edited, but some of them will not run if they require a moderate or heavy computation/memory resources, and no local server is being used.
 
[[File:Fōrmulæ - FizzBuzz 01.png]]
In '''[https://formulae.org/?example=FizzBuzz this]''' page you can see the program(s) related to this task and their results.
 
[[File:Fōrmulæ - FizzBuzz 01a.png]]
 
[[File:Fōrmulæ - FizzBuzz 02.png]]
 
=={{header|Gambas}}==
Line 4,330 ⟶ 4,742:
od;
end;</syntaxhighlight>
 
=={{header|GDScript}}==
<syntaxhighlight lang="gdscript">
extends Node
 
func _ready():
for i in range(1, 101):
if i % 15 == 0:
print("FizzBuzz")
elif i % 3 == 0:
print("Fizz")
elif i % 5 == 0:
print("Buzz")
else:
print(i)
 
get_tree().quit()
</syntaxhighlight>
 
=={{header|Genyris}}==
Line 4,877 ⟶ 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,430 ⟶ 5,871:
 
=={{header|Julia}}==
{{works with|Julia|01.68.5}}
 
One basic solution:
Line 5,449 ⟶ 5,890:
 
A 3rd possible solution:
<syntaxhighlight lang="julia">fb(i::Integer) = "Fizz" ^ (i % 3 == 0) * "Buzz" ^ (i % 5 == 0) * decstring(i) ^ (i % 3 != 0 && i % 5 != 0)
for i in 1:100 println(fb(i)) end</syntaxhighlight>
 
Line 5,707 ⟶ 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,742 ⟶ 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}}==
 
Lean 4:
 
<syntaxhighlight lang="lean">
def fizz : String :=
"Fizz"
 
def buzz : String :=
"Buzz"
 
def newLine : String :=
"\n"
 
def isDivisibleBy (n : Nat) (m : Nat) : Bool :=
match m with
| 0 => false
| (k + 1) => (n % (k + 1)) = 0
 
def getTerm (n : Nat) : String :=
if (isDivisibleBy n 15) then (fizz ++ buzz)
else if (isDivisibleBy n 3) then fizz
else if (isDivisibleBy n 5) then buzz
else toString (n)
 
def range (a : Nat) (b : Nat) : List (Nat) :=
match b with
| 0 => []
| m + 1 => a :: (range (a + 1) m)
 
def getTerms (n : Nat) : List (String) :=
(range 1 n).map (getTerm)
 
def addNewLine (accum : String) (elem : String) : String :=
accum ++ elem ++ newLine
 
def fizzBuzz : String :=
(getTerms 100).foldl (addNewLine) ("")
 
def main : IO Unit :=
IO.println (fizzBuzz)
 
#eval main
</syntaxhighlight>
 
 
=={{header|Liberty BASIC}}==
Line 5,991 ⟶ 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,063 ⟶ 6,595:
`ifelse(eval(x%5==0),1,Buzz,x)')')
')</syntaxhighlight>
 
=={{header|MACRO-11}}==
<syntaxhighlight lang="macro11"> .TITLE FIZBUZ
.MCALL .TTYOUT,.EXIT
FIZBUZ::MOV #1,R2 ; COUNTER
MOV #3,R3 ; FIZZ COUNTER
MOV #5,R4 ; BUZZ COUNTER
NUMBER: CLR R5
CHKFIZ: DEC R3
BNE CHKBUZ
MOV #FIZZ,R1
JSR PC,PRSTR
MOV #3,R3
INC R5
CHKBUZ: DEC R4
BNE CHKNUM
MOV #BUZZ,R1
JSR PC,PRSTR
MOV #5,R4
INC R5
CHKNUM: TST R5
BNE NEXNUM
MOV R2,R0
JSR PC,PR0
NEXNUM: MOV #NL,R1
JSR PC,PRSTR
INC R2
CMP R2,#^D100
BLE NUMBER
.EXIT
; STRING DATA
FIZZ: .ASCIZ /FIZZ/
BUZZ: .ASCIZ /BUZZ/
NL: .BYTE 15,12,0
.EVEN
; PRINT NUMBER IN R0 AS DECIMAL
PR0: MOV R2,-(SP)
MOV #4$,R1
1$: MOV #-1,R2
2$: INC R2
SUB #12,R0
BCC 2$
ADD #72,R0
MOVB R0,-(R1)
MOV R2,R0
BNE 1$
3$: MOVB (R1)+,R0
.TTYOUT
BNE 3$
MOV (SP)+,R2
RTS PC
.ASCII /...../
4$: .BYTE 0
; PRINT STRING IN R1
PRSTR: MOVB (R1)+,R0
.TTYOUT
BNE PRSTR
RTS PC
.END FIZBUZ</syntaxhighlight>
 
=={{header|MAD}}==
<syntaxhighlight lang="mad"> NORMAL MODE IS INTEGER
VECTOR VALUES FIZZ = $4HFIZZ*$
VECTOR VALUES BUZZ = $4HBUZZ*$
VECTOR VALUES FIBU = $8HFIZZBUZZ*$
VECTOR VALUES NUM = $I2*$
 
INTERNAL FUNCTION REM.(A,B) = A-(A/B)*B
 
THROUGH LOOP, FOR I = 1, 1, I .G. 100
WHENEVER REM.(I,15).E.0
PRINT FORMAT FIBU
OR WHENEVER REM.(I,5).E.0
PRINT FORMAT BUZZ
OR WHENEVER REM.(I,3).E.0
PRINT FORMAT FIZZ
OTHERWISE
PRINT FORMAT NUM,I
LOOP END OF CONDITIONAL
 
END OF PROGRAM</syntaxhighlight>
 
=={{header|make}}==
Line 6,137 ⟶ 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,172 ⟶ 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 6,389 ⟶ 7,029:
end
end</syntaxhighlight>
 
=={{header|Miranda}}==
<syntaxhighlight lang="miranda">main :: [sys_message]
main = [Stdout (lay (map fizzbuzz [1..100]))]
 
fizzbuzz :: num->[char]
fizzbuzz n = "FizzBuzz", if n mod 15 = 0
= "Fizz", if n mod 3 = 0
= "Buzz", if n mod 5 = 0
= show n, otherwise</syntaxhighlight>
 
=={{header|ML}}==
Line 6,892 ⟶ 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,019 ⟶ 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 7,079 ⟶ 7,758:
{Show {FizzBuzz I}}
end</syntaxhighlight>
 
=={{header|Palo Alto Tiny BASIC}}==
See [[FizzBuzz/Basic#Palo Alto Tiny BASIC|FizzBuzz/Basic]].
 
=={{header|PARI/GP}}==
Line 8,053 ⟶ 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,490 ⟶ 9,188:
=={{header|Python}}==
===Python2: Simple===
<syntaxhighlight lang="python">for i in xrangerange(1, 101):
if i % 15 == 0:
print "FizzBuzz"
Line 8,621 ⟶ 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,643 ⟶ 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 8,822 ⟶ 9,544:
 
=={{header|Red}}==
<syntaxhighlight lang="rebolred">Red [Title: "FizzBuzz"]
 
repeat i 100 [
Line 8,832 ⟶ 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,116 ⟶ 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}}==
Structured programming:
≪ { } 1 100 '''FOR''' j
'''IF''' j 3 MOD '''THEN''' "" '''ELSE''' "Fizz" '''END'''
'''IF''' j 5 MOD NOT '''THEN''' "Buzz" + '''END'''
'''IF''' DUP SIZE NOT '''THEN''' DROP j '''END'''
+ '''NEXT'''
≫ ''''FIZZB'''' STO
Arithmetic:
≪ { } 1 100 '''FOR''' j
j 3 MOD NOT j 5 MOD NOT → a b
≪ '''IF''' a b + '''THEN''' "FizzBuzz" 5 4 a * - a b 2 * MAX 4 * SUB '''ELSE''' j '''END'''
≫ + '''NEXT'''
≫ ''''FIZZB'''' STO
Data-centric:
≪ "FizzBuzz" { (1,4) (5,8) (1,8) } → fb idx
≪ { } 1 100 '''FOR''' j
'''IF''' j 3 MOD NOT j 5 MOD NOT 2 * + '''THEN''' fb idx LAST GET C→R SUB '''ELSE''' j '''END'''
+ '''NEXT'''
≫ ≫ ''''FIZZB'''' STO
Esoteric one-liner:
≪ ≪ j ROT MOD "" ROT IFTE ≫ → f ≪ { } 1 100 FOR j 3 "Fizz" f EVAL 5 "Buzz" f EVAL + SIZE LAST j IFTE + NEXT ≫ ≫ EVAL
 
=={{header|Ruby}}==
Line 9,718 ⟶ 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 9,805 ⟶ 10,596:
=={{header|Sidef}}==
Structured:
<syntaxhighlight lang="rubyperl">{ |i|
if (i %% 3) {
print "Fizz"
Line 9,813 ⟶ 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 9,824 ⟶ 10,615:
 
One-liner:
<syntaxhighlight lang="ruby">{|i|say >"#{<Fizz>[i.%3]}#{<Buzz>[i.%5]}"||i_}*<<1..100</syntaxhighlight>
 
=={{header|Simula}}==
Line 10,055 ⟶ 10,846:
ORDER BY n ASC
OPTION ( MAXRECURSION 100 )</syntaxhighlight>
 
===SQL Anywhere specific - minimalist===
<syntaxhighlight lang="sql">SELECT
isnull(if row_num % 3 = 0 then 'Fizz' endif + if row_num % 5 = 0 then 'Buzz' endif, str(row_num))
FROM
sa_rowgenerator(1,100)</syntaxhighlight>
===Generic SQL using a join===
This should work in most RDBMSs, but you may need to change <tt>MOD(i,divisor)</tt> to <tt>i % divisor</tt>.
Line 10,155 ⟶ 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,343 ⟶ 11,172:
See [[FizzBuzz/Assembly]]
 
=={{header|TI-99/4a TI BASIC / Extended BASIC}}==
See [[FizzBuzz/AssemblyBasic]]
 
=={{Header|Tiny BASIC}}==
Line 10,483 ⟶ 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 10,553 ⟶ 11,387:
return 0;;
}</syntaxhighlight>
 
=={{header|Vale}}==
{{works with|Vale|0.2.0}}
<syntaxhighlight lang="vale">
import stdlib.*;
 
exported func main(){
fizzBuzz(1, 100);
}
 
func fizzBuzz(i int, stop int) {
result = if i.mod(3) == 0 {
"Fizz" } else { ""
} + if i.mod(5) == 0 {
"Buzz" } else { ""
};
 
println(if result == "" { i.str() } else { result });
 
if i < stop {
return fizzBuzz(i + 1, stop);
}
}
</syntaxhighlight>
 
=={{header|VAX Assembly}}==
Line 11,006 ⟶ 11,864:
 
=={{header|Wren}}==
<syntaxhighlight lang="ecmascriptwren">for (i in 1..100) {
if (i % 15 == 0) {
System.print("FizzBuzz")
Line 11,440 ⟶ 12,298:
See [[FizzBuzz/Basic]]
 
 
=={{header|YAMLScript}}==
 
<syntaxhighlight lang="yaml">
#!/usr/bin/env ys-0
 
# This program has multiple implementations of "fizzbuzz".
 
# 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(x):
cond:
zero?(x % 15): 'FizzBuzz'
zero?(x % 5): 'Buzz'
zero?(x % 3): 'Fizz'
=>: x
=>: 1 .. n
 
defn fizzbuzz-2(n):
loop [i 1, l []]:
if (i > n):
=>: l
recur inc(i):
conj l:
cond:
zero?(i % 15): 'FizzBuzz'
zero?(i % 5): 'Buzz'
zero?(i % 3): 'Fizz'
=>: i
 
defn fizzbuzz-3(n):
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