Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,7 @@
---
category:
- Iteration
- Recursion
- Simple
from: http://rosettacode.org/wiki/FizzBuzz
note: Classic CS problems and programs

18
Task/FizzBuzz/00-TASK.txt Normal file
View file

@ -0,0 +1,18 @@
;Task:
Write a program that prints the integers from   '''1'''   to   '''100'''   (inclusive).
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)
The   ''FizzBuzz''   problem was presented as the lowest level of comprehension required to illustrate adequacy.
;Also see:
*   (a blog)   [http://weblog.raganwald.com/2007/01/dont-overthink-fizzbuzz.html dont-overthink-fizzbuzz]
*   (a blog)   [http://blog.codinghorror.com/fizzbuzz-the-programmers-stairway-to-heaven/ fizzbuzz-the-programmers-stairway-to-heaven]
<br><br>

View file

@ -0,0 +1,9 @@
L(i) 1..100
I i % 15 == 0
print(FizzBuzz)
E I i % 3 == 0
print(Fizz)
E I i % 5 == 0
print(Buzz)
E
print(i)

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,94 @@
/* ARM assembly AARCH64 Raspberry PI 3B */
/* program FizzBuzz64.s */
/*******************************************/
/* Constantes file */
/*******************************************/
/* for this file see task include a file in language AArch64 assembly*/
.include "../includeConstantesARM64.inc"
/*******************************************/
/* Initialized data */
/*******************************************/
.data
szMessFizz: .asciz "Fizz\n"
szMessBuzz: .asciz "Buzz\n"
szMessFizzBuzz: .asciz "FizzBuzz\n"
szMessNumber: .asciz "Number : @ "
szCarriageReturn: .asciz "\n"
/*******************************************/
/* UnInitialized data */
/*******************************************/
.bss
sZoneConv: .skip 24
/*******************************************/
/* code section */
/*******************************************/
.text
.global main
main: // entry of program
mov x10,3 // divisor 3
mov x11,5 // divisor 5
mov x12,15 // divisor 15
mov x13,1 // indice
1: // loop begin
udiv x14,x13,x12 // multiple 15
msub x15,x14,x12,x13 // remainder
cbnz x15,2f // zero ?
mov x0,x13
ldr x1,qAdrszMessFizzBuzz
bl displayResult
b 4f
2: // multiple 3
udiv x14,x13,x10
msub x15,x14,x10,x13 // remainder
cbnz x15,3f // zero ?
mov x0,x13
ldr x1,qAdrszMessFizz
bl displayResult
b 4f
3: // multiple 5
udiv x14,x13,x11
msub x15,x14,x11,x13 // remainder
cbnz x15,4f // zero ?
mov x0,x13
ldr x1,qAdrszMessBuzz
bl displayResult
4:
add x13,x13,1 // increment indice
cmp x13,100 // maxi ?
ble 1b
100: // standard end of the program
mov x8,EXIT // request to exit program
svc 0 // perform the system call
qAdrszMessFizzBuzz: .quad szMessFizzBuzz
qAdrszMessFizz: .quad szMessFizz
qAdrszMessBuzz: .quad szMessBuzz
/******************************************************************/
/* Display résult */
/******************************************************************/
/* x0 contains the number*/
/* x1 contains display string address */
displayResult:
stp x2,lr,[sp,-16]! // save registers
mov x2,x1
ldr x1,qAdrsZoneConv // conversion number
bl conversion10S // decimal conversion
ldr x0,qAdrszMessNumber
ldr x1,qAdrsZoneConv
bl strInsertAtCharInc // insert result at @ character
bl affichageMess // display message final
mov x0,x2
bl affichageMess
ldp x2,lr,[sp],16 // restaur 2 registers
ret // return to address lr x30
qAdrsZoneConv: .quad sZoneConv
qAdrszMessNumber: .quad szMessNumber
/********************************************************/
/* File Include fonctions */
/********************************************************/
/* for this file see task include a file in language AArch64 assembly */
.include "../includeARM64.inc"

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,5 @@
cl_demo_output=>display( value stringtab( for i = 1 until i > 100
let fizz = cond #( when i mod 3 = 0 then |fizz| else space )
buzz = cond #( when i mod 5 = 0 then |buzz| else space )
fb = |{ fizz }{ buzz }| in
( switch #( fb when space then i else fb ) ) ) ).

View file

@ -0,0 +1,12 @@
(defun fizzbuzz-r (i)
(declare (xargs :measure (nfix (- 100 i))))
(prog2$
(cond ((= (mod i 15) 0) (cw "FizzBuzz~%"))
((= (mod i 5) 0) (cw "Buzz~%"))
((= (mod i 3) 0) (cw "Fizz~%"))
(t (cw "~x0~%" i)))
(if (zp (- 100 i))
nil
(fizzbuzz-r (1+ i)))))
(defun fizzbuzz () (fizzbuzz-r 1))

View file

@ -0,0 +1,15 @@
main:(
FOR i TO 100 DO
printf(($gl$,
IF i %* 15 = 0 THEN
"FizzBuzz"
ELIF i %* 3 = 0 THEN
"Fizz"
ELIF i %* 5 = 0 THEN
"Buzz"
ELSE
i
FI
))
OD
)

View file

@ -0,0 +1 @@
FOR i TO 100 DO print(((i%*15=0|"FizzBuzz"|:i%*3=0|"Fizz"|:i%*5=0|"Buzz"|i),new line)) OD

View file

@ -0,0 +1,23 @@
BEGIN
INTEGER FUNCTION DIVBY(N, D);
INTEGER N;
INTEGER D;
BEGIN
DIVBY := 1 - (N - D * (N / D));
END;
INTEGER I;
FOR I := 1 STEP 1 UNTIL 100 DO
BEGIN
IF DIVBY(I, 15) = 1 THEN
WRITE("FizzBuzz")
ELSE IF DIVBY(I, 5) = 1 THEN
WRITE("Buzz")
ELSE IF DIVBY(I, 3) = 1 THEN
WRITE("Fizz")
ELSE
WRITE(I);
END;
END

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,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,2 @@
⎕IO0
(L,'Fizz' 'Buzz' 'FizzBuzz')[¯1+(L×W=0)+W(100×~0=W)+W+/1 2×0=3 5|L1+100]

View file

@ -0,0 +1 @@
A[I]1+I(0A)/A('FIZZBUZZ' 'FIZZ 'BUZZ' 0)[2¨×(3 5)|¨1+100]

View file

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

View file

@ -0,0 +1 @@
{(FizzBuzz Fizz Buzz,)[(0=15 3 5|)1]}¨100

View file

@ -0,0 +1,40 @@
sv fizzbuzz n; t;d
[1] ⍝⍝ Solve the popular 'fizzbuzz' problem in APL.
[2] ⍝⍝ \param n - highest number to compute (≥0)
[3] ⍝⍝ \returns sv - a vector of strings representing the fizzbuzz solution for n
[4] ⍝⍝ (note we return a string vector to avoid a mixed-type result; remove the
[5] ⍝⍝ ⍕ function from the (⍕t[⍵]) term to see the difference).
[6] ⍝⍝⍝⍝
[7] tn ⍝ the sequence 1..n itself which we'll pick from
[8] ⍝ ... or the words 'fizz', 'buzz', 'fizzbuzz' depending on
[9] ⍝ ... divisibility by 3 and/or 5
[10] ⍝⎕←t ⍝ (Uncomment to see during call)
[11]
[12] d1+(+ {((0=3|)) (2×(0=5|))} n)
[13] ⍝ || || | | | ↓↓
[14] ⍝ || || | | | n: generate range (1..n)
[15] ⍝ || || | ↓.....................↓ ↓↓
[16] ⍝ || || | A dfn (lambda) taking its right arg (⍵, n here) to compute two boolean
[17] ⍝ || || | vectors(v12): divisibility by 3 and 5, respectively, for each of n
[18] ⍝ || || ↓
[19] ⍝ || || ⊃: Disclose ('lift-up' and pad w/zeros) the 'ragged' matrix of vectors (v12)
[20] ⍝ || || holding divisibility by 3 and 5 of each n
[21] ⍝ || ↓↓
[22] ⍝ || +⌿: Sum (v12) row-wise to count divisibility (0=neither 3 nor 5, 1=3, 2=3 and 5)
[23] ⍝ ↓↓
[24] ⍝ 1+: Add one to (v12) to make them 1-based for indexing below:
[25] ⍝⎕←d
[26]
[27] sv { ((t[]) 'Fizz' 'Buzz' 'FizzBuzz') [d[]]}¨ n
[28] ⍝ | | | | | |
[29] ⍝ | | | ↓....↓ |
[30] ⍝ | |................................↓ idx |
[31] ⍝ | ( lookup output vector ) |
[32] ⍝ ↓...........................................↓
[33] ⍝ A dfn (lambda) taking as its right arg (⍵) n and using the 'each' (¨)
[34] ⍝ operator to apply the lambda to each (idx) of n.
[35]
[36] ⍝⍝ USAGE
[37] ⍝⍝ ⎕ ← ,fizzbuzz 15
[38] ⍝ 1 2 Fizz 4 Buzz Fizz 7 8 Fizz Buzz 11 Fizz 13 14 FizzBuzz

View file

@ -0,0 +1,119 @@
/ * linux GAS */
.global _start
.data
Fizz: .ascii "Fizz\n"
Buzz: .ascii "Buzz\n"
FizzAndBuzz: .ascii "FizzBuzz\n"
numstr_buffer: .skip 3
newLine: .ascii "\n"
.text
_start:
bl FizzBuzz
mov r7, #1
mov r0, #0
svc #0
FizzBuzz:
push {lr}
mov r9, #100
fizzbuzz_loop:
mov r0, r9
mov r1, #15
bl divide
cmp r1, #0
ldreq r1, =FizzAndBuzz
moveq r2, #9
beq fizzbuzz_print
mov r0, r9
mov r1, #3
bl divide
cmp r1, #0
ldreq r1, =Fizz
moveq r2, #5
beq fizzbuzz_print
mov r0, r9
mov r1, #5
bl divide
cmp r1, #0
ldreq r1, =Buzz
moveq r2, #5
beq fizzbuzz_print
mov r0, r9
bl make_num
mov r2, r1
mov r1, r0
fizzbuzz_print:
mov r0, #1
mov r7, #4
svc #0
sub r9, #1
cmp r9, #0
bgt fizzbuzz_loop
pop {lr}
mov pc, lr
make_num:
push {lr}
ldr r4, =numstr_buffer
mov r5, #4
mov r6, #1
mov r1, #100
bl divide
cmp r0, #0
subeq r5, #1
movne r6, #0
add r0, #48
strb r0, [r4, #0]
mov r0, r1
mov r1, #10
bl divide
cmp r0, #0
movne r6, #0
cmp r6, #1
subeq r5, #1
add r0, #48
strb r0, [r4, #1]
add r1, #48
strb r1, [r4, #2]
mov r2, #4
sub r0, r2, r5
add r0, r4, r0
mov r1, r5
pop {lr}
mov pc, lr
divide:
udiv r2, r0, r1
mul r3, r1, r2
sub r1, r0, r3
mov r0, r2
mov pc, lr

View file

@ -0,0 +1,18 @@
#include "share/atspre_staload.hats"
implement main0() = loop(1, 100) where {
fun loop(from: int, to: int): void =
if from > to then () else
let
val by3 = (from % 3 = 0)
val by5 = (from % 5 = 0)
in
case+ (by3, by5) of
| (true, true) => print_string("FizzBuzz")
| (true, false) => print_string("Fizz")
| (false, true) => print_string("Buzz")
| (false, false) => print_int(from);
print_newline();
loop(from+1, to)
end
}

View file

@ -0,0 +1,22 @@
PROC Main()
BYTE i,d3,d5
d3=1 d5=1
FOR i=1 TO 100
DO
IF d3=0 AND d5=0 THEN
Print("FizzBuzz")
ELSEIF d3=0 THEN
Print("Fizz")
ELSEIF d5=0 THEN
Print("Buzz")
ELSE
PrintB(i)
FI
Put(32)
d3==+1 d5==+1
IF d3=3 THEN d3=0 FI
IF d5=5 THEN d5=0 FI
OD
RETURN

View file

@ -0,0 +1,10 @@
for (var i:int = 1; i <= 100; i++) {
if (i % 15 == 0)
trace('FizzBuzz');
else if (i % 5 == 0)
trace('Buzz');
else if (i % 3 == 0)
trace('Fizz');
else
trace(i);
}

View file

@ -0,0 +1,16 @@
with Ada.Text_IO; use Ada.Text_IO;
procedure Fizzbuzz is
begin
for I in 1..100 loop
if I mod 15 = 0 then
Put_Line("FizzBuzz");
elsif I mod 5 = 0 then
Put_Line("Buzz");
elsif I mod 3 = 0 then
Put_Line("Fizz");
else
Put_Line(Integer'Image(I));
end if;
end loop;
end Fizzbuzz;

View file

@ -0,0 +1,49 @@
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

View file

@ -0,0 +1,10 @@
for(integer i=1; i <= 100; i++){
String output = '';
if(math.mod(i, 3) == 0) output += 'Fizz';
if(math.mod(i, 5) == 0) output += 'Buzz';
if(output != ''){
System.debug(output);
} else {
System.debug(i);
}
}

View file

@ -0,0 +1,14 @@
property outputText: ""
repeat with i from 1 to 100
if i mod 15 = 0 then
set outputText to outputText & "FizzBuzz"
else if i mod 3 = 0 then
set outputText to outputText & "Fizz"
else if i mod 5 = 0 then
set outputText to outputText & "Buzz"
else
set outputText to outputText & i
end if
set outputText to outputText & linefeed
end repeat
outputText

View file

@ -0,0 +1,28 @@
on fizzBuzz(n)
script o
property output : {}
end script
repeat with i from 1 to n
if (i mod 3 = 0) then
if (i mod 15 = 0) then
set end of o's output to "FizzBuzz"
else
set end of o's output to "Fizz"
end if
else if (i mod 5 = 0) then
set end of o's output to "Buzz"
else
set end of o's output to i
end if
end repeat
set astid to AppleScript's text item delimiters
set AppleScript's text item delimiters to linefeed
set output to o's output as text
set AppleScript's text item delimiters to astid
return output
end fizzBuzz
fizzBuzz(100)

View file

@ -0,0 +1,24 @@
on fizzBuzz(n)
script o
property output : {}
end script
repeat with i from 1 to n
set end of o's output to i
end repeat
repeat with x in {{3, "Fizz"}, {5, "Buzz"}, {15, "FizzBuzz"}}
set {m, t} to x
repeat with i from m to n by m
set item i of o's output to t
end repeat
end repeat
set astid to AppleScript's text item delimiters
set AppleScript's text item delimiters to linefeed
set output to o's output as text
set AppleScript's text item delimiters to astid
return output
end fizzBuzz
fizzBuzz(100)

View file

@ -0,0 +1,94 @@
------------------------- FIZZBUZZ -------------------------
-- fizz :: Int -> Bool
on fizz(n)
n mod 3 = 0
end fizz
-- buzz :: Int -> Bool
on buzz(n)
n mod 5 = 0
end buzz
-- fizzAndBuzz :: Int -> Bool
on fizzAndBuzz(n)
n mod 15 = 0
end fizzAndBuzz
-- fizzBuzz :: Int -> String
on fizzBuzz(x)
caseOf(x, [[my fizzAndBuzz, "FizzBuzz"], ¬
[my fizz, "Fizz"], ¬
[my buzz, "Buzz"]], x as string)
end fizzBuzz
--------------------------- TEST ---------------------------
on run
intercalate(linefeed, ¬
map(fizzBuzz, enumFromTo(1, 100)))
end run
-------------------- GENERIC FUNCTIONS ---------------------
-- caseOf :: a -> [(predicate, b)] -> Maybe b -> Maybe b
on caseOf(e, lstPV, default)
repeat with lstCase in lstPV
set {p, v} to contents of lstCase
if mReturn(p)'s |λ|(e) then return v
end repeat
return default
end caseOf
-- enumFromTo :: Int -> Int -> [Int]
on enumFromTo(m, n)
if m > n then
set d to -1
else
set d to 1
end if
set lst to {}
repeat with i from m to n by d
set end of lst to i
end repeat
return lst
end enumFromTo
-- intercalate :: Text -> [Text] -> Text
on intercalate(strText, lstText)
set {dlm, my text item delimiters} to {my text item delimiters, strText}
set strJoined to lstText as text
set my text item delimiters to dlm
return strJoined
end intercalate
-- map :: (a -> b) -> [a] -> [b]
on map(f, xs)
tell mReturn(f)
set lng to length of xs
set lst to {}
repeat with i from 1 to lng
set end of lst to |λ|(item i of xs, i, xs)
end repeat
return lst
end tell
end map
-- Lift 2nd class handler function into 1st class script wrapper
-- mReturn :: Handler -> Script
on mReturn(f)
if class of f is script then
f
else
script
property |λ| : f
end script
end if
end mReturn

View file

@ -0,0 +1,15 @@
fizzbuzz():
for x in [1..100]
if x%5==0 and x%3==0
return "FizzBuzz"
else
if x%3==0
return "Fizz"
else
if x%5==0
return "Buzz"
else
return x
main():
fizzbuzz() -> io

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,7 @@
loop 1..100 [x][
case []
when? [0=x%15] -> print "FizzBuzz"
when? [0=x%3] -> print "Fizz"
when? [0=x%5] -> print "Buzz"
else -> print x
]

View file

@ -0,0 +1,15 @@
for(int number = 1; number <= 100; ++number) {
if (number % 15 == 0) {
write("FizzBuzz");
} else {
if (number % 3 == 0) {
write("Fizz");
} else {
if (number % 5 == 0) {
write("Buzz");
} else {
write(number);
}
}
}
}

View file

@ -0,0 +1,14 @@
Loop, 100
{
If (Mod(A_Index, 15) = 0)
output .= "FizzBuzz`n"
Else If (Mod(A_Index, 3) = 0)
output .= "Fizz`n"
Else If (Mod(A_Index, 5) = 0)
output .= "Buzz`n"
Else
output .= A_Index "`n"
}
FileDelete, output.txt
FileAppend, %output%, output.txt
Run, cmd /k type output.txt

View file

@ -0,0 +1,7 @@
Gui, Add, Edit, r20
Gui,Show
Loop, 100
Send, % (!Mod(A_Index, 15) ? "FizzBuzz" : !Mod(A_Index, 3) ? "Fizz" : !Mod(A_Index, 5) ? "Buzz" : A_Index) "`n"
Return
Esc::
ExitApp

View file

@ -0,0 +1,11 @@
For $i = 1 To 100
If Mod($i, 15) = 0 Then
MsgBox(0, "FizzBuzz", "FizzBuzz")
ElseIf Mod($i, 5) = 0 Then
MsgBox(0, "FizzBuzz", "Buzz")
ElseIf Mod($i, 3) = 0 Then
MsgBox(0, "FizzBuzz", "Fizz")
Else
MsgBox(0, "FizzBuzz", $i)
EndIf
Next

View file

@ -0,0 +1,25 @@
#include <Constants.au3>
; uncomment how you want to do the output
Func Out($Msg)
ConsoleWrite($Msg & @CRLF)
;~ FileWriteLine("FizzBuzz.Log", $Msg)
;~ $Btn = MsgBox($MB_OKCANCEL + $MB_ICONINFORMATION, "FizzBuzz", $Msg)
;~ If $Btn > 1 Then Exit ; Pressing 'Cancel'-button aborts the program
EndFunc ;==>Out
Out("# FizzBuzz:")
For $i = 1 To 100
If Mod($i, 15) = 0 Then
Out("FizzBuzz")
ElseIf Mod($i, 5) = 0 Then
Out("Buzz")
ElseIf Mod($i, 3) = 0 Then
Out("Fizz")
Else
Out($i)
EndIf
Next
Out("# Done.")

View file

@ -0,0 +1,8 @@
For each i from 1 to 100 do [
Print:
if i mod 15 = 0 then ["FizzBuzz"]
else if i mod 3 = 0 then ["Fizz"]
else if i mod 5 = 0 then ["Buzz"]
else [“i”]
++ "\n";
];

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,18 @@
GET "libhdr"
LET start() BE $(
FOR i=1 TO 100 DO $(
TEST (i REM 15) = 0 THEN
writes("FizzBuzz")
ELSE TEST (i REM 3) = 0 THEN
writes("Fizz")
ELSE TEST (i REM 5) = 0 THEN
writes("Buzz")
ELSE
writen(i, 0)
newline()
$)
$)

View file

@ -0,0 +1 @@
(´"Fizz""Buzz"/˜·(¬´)0=35|)¨1+100

View file

@ -0,0 +1 @@
((´"fizz""buzz"/˜0=35|))¨1+100

View file

@ -0,0 +1,22 @@
main:
{ { iter 1 + dup
15 %
{ "FizzBuzz" <<
zap }
{ dup
3 %
{ "Fizz" <<
zap }
{ dup
5 %
{ "Buzz" <<
zap}
{ %d << }
if }
if }
if
"\n" << }
100 times }

View file

@ -0,0 +1,24 @@
@echo off
for /L %%i in (1,1,100) do call :tester %%i
goto :eof
:tester
set /a test = %1 %% 15
if %test% NEQ 0 goto :NotFizzBuzz
echo FizzBuzz
goto :eof
:NotFizzBuzz
set /a test = %1 %% 5
if %test% NEQ 0 goto :NotBuzz
echo Buzz
goto :eof
:NotBuzz
set /a test = %1 %% 3
if %test% NEQ 0 goto :NotFizz
echo Fizz
goto :eof
:NotFizz
echo %1

View file

@ -0,0 +1,29 @@
@echo off
set n=1
:loop
call :tester %n%
set /a n += 1
if %n% LSS 101 goto loop
goto :eof
:tester
set /a test = %1 %% 15
if %test% NEQ 0 goto :NotFizzBuzz
echo FizzBuzz
goto :eof
:NotFizzBuzz
set /a test = %1 %% 5
if %test% NEQ 0 goto :NotBuzz
echo Buzz
goto :eof
:NotBuzz
set /a test = %1 %% 3
if %test% NEQ 0 goto :NotFizz
echo Fizz
goto :eof
:NotFizz
echo %1

View file

@ -0,0 +1,10 @@
@echo off & setlocal enabledelayedexpansion
for /l %%i in (1,1,100) do (
set /a m5=%%i %% 5
set /a m3=%%i %% 3
set s=
if !m5! equ 0 set s=!s!Fizz
if !m3! equ 0 set s=!s!Buzz
if "!s!"=="" set s=%%i
echo !s!
)

View file

@ -0,0 +1,9 @@
for (i = 1; i <= 100; i++) {
w = 0
if (i % 3 == 0) { "Fizz"; w = 1; }
if (i % 5 == 0) { "Buzz"; w = 1; }
if (w == 0) i
if (w == 1) "
"
}
quit

View file

@ -0,0 +1,4 @@
> q
>@F5~%"d@F{ > @F q
_1>F3~%'d`Fizz`@F5~%'d >`Buzz`@FNp
;bL@~.~4~.5~5@ P<

View file

@ -0,0 +1,4 @@
>@?q
> q >Ag'd@{?p
_>"1F3~%'d`Fizz`f>@F5~%'d`Buzz`@p
b P~;"-~@~.+0~P9@N?<

View file

@ -0,0 +1,13 @@
for i = 0; i <= 100; i++
out = ""
if i % 3 == 0
out = "Fizz"
end
if i % 5 == 0
out = out + "Buzz"
end
if out == ""
out = i
end
print(out)
end

View file

@ -0,0 +1,12 @@
def fizzbuzz(size):
for i in range(1, size):
if i%15 == 0:
print 'FizzBuzz'
elif i%5 == 0:
print 'Buzz'
elif i%3 == 0:
print 'Fizz'
else:
print i
fizzbuzz(101)

View file

@ -0,0 +1 @@
0:?i&whl'(1+!i:<101:?i&out$(mod$(!i.3):0&(mod$(!i.5):0&FizzBuzz|Fizz)|mod$(!i.5):0&Buzz|!i))

View file

@ -0,0 +1,12 @@
0:?i
& whl
' ( 1+!i:<101:?i
& out
$ ( mod$(!i.3):0
& ( mod$(!i.5):0&FizzBuzz
| Fizz
)
| mod$(!i.5):0&Buzz
| !i
)
)

View file

@ -0,0 +1,11 @@
1.to 100 { n |
true? n % 15 == 0
{ p "FizzBuzz" }
{ true? n % 3 == 0
{ p "Fizz" }
{ true? n % 5 == 0
{ p "Buzz" }
{ p n }
}
}
}

View file

@ -0,0 +1,39 @@
#include <iostream>
#include <chrono>
int main()
{
int fizz = 0, buzz = 0, fizzbuzz = 0;
bool isFizz = false;
auto startTime = std::chrono::high_resolution_clock::now();
for (unsigned int i = 1; i <= 4000000000; i++) {
isFizz = false;
if (i % 3 == 0) {
isFizz = true;
fizz++;
}
if (i % 5 == 0) {
if (isFizz) {
fizz--;
fizzbuzz++;
}
else {
buzz++;
}
}
}
auto endTime = std::chrono::high_resolution_clock::now();
auto totalTime = endTime - startTime;
printf("\t fizz : %d, buzz: %d, fizzbuzz: %d, duration %lld milliseconds\n", fizz, buzz, fizzbuzz, (totalTime / std::chrono::milliseconds(1)));
return 0;
}

View file

@ -0,0 +1,18 @@
#include <iostream>
using namespace std;
int main ()
{
for (int i = 1; i <= 100; i++)
{
if ((i % 15) == 0)
cout << "FizzBuzz\n";
else if ((i % 3) == 0)
cout << "Fizz\n";
else if ((i % 5) == 0)
cout << "Buzz\n";
else
cout << i << "\n";
}
return 0;
}

View file

@ -0,0 +1,19 @@
#include <iostream>
using namespace std;
int main()
{
for (int i = 0; i <= 100; ++i)
{
bool fizz = (i % 3) == 0;
bool buzz = (i % 5) == 0;
if (fizz)
cout << "Fizz";
if (buzz)
cout << "Buzz";
if (!fizz && !buzz)
cout << i;
cout << "\n";
}
return 0;
}

View file

@ -0,0 +1,16 @@
#include <iostream>
int main()
{
int i, f = 2, b = 4;
for ( i = 1 ; i <= 100 ; ++i, --f, --b )
{
if ( f && b ) { std::cout << i; }
if ( !f ) { std::cout << "Fizz"; f = 3; }
if ( !b ) { std::cout << "Buzz"; b = 5; }
std::cout << std::endl;
}
return 0;
}

View file

@ -0,0 +1,25 @@
#include <iostream>
#include <algorithm>
#include <vector>
int main()
{
std::vector<int> range(100);
std::iota(range.begin(), range.end(), 1);
std::vector<std::string> values;
values.resize(range.size());
auto fizzbuzz = [](int i) -> std::string {
if ((i%15) == 0) return "FizzBuzz";
if ((i%5) == 0) return "Buzz";
if ((i%3) == 0) return "Fizz";
return std::to_string(i);
};
std::transform(range.begin(), range.end(), values.begin(), fizzbuzz);
for (auto& str: values) std::cout << str << std::endl;
return 0;
}

View file

@ -0,0 +1,48 @@
#include <iostream>
template <int n, int m3, int m5>
struct fizzbuzz : fizzbuzz<n-1, (n-1)%3, (n-1)%5>
{
fizzbuzz()
{ std::cout << n << std::endl; }
};
template <int n>
struct fizzbuzz<n, 0, 0> : fizzbuzz<n-1, (n-1)%3, (n-1)%5>
{
fizzbuzz()
{ std::cout << "FizzBuzz" << std::endl; }
};
template <int n, int p>
struct fizzbuzz<n, 0, p> : fizzbuzz<n-1, (n-1)%3, (n-1)%5>
{
fizzbuzz()
{ std::cout << "Fizz" << std::endl; }
};
template <int n, int p>
struct fizzbuzz<n, p, 0> : fizzbuzz<n-1, (n-1)%3, (n-1)%5>
{
fizzbuzz()
{ std::cout << "Buzz" << std::endl; }
};
template <>
struct fizzbuzz<0,0,0>
{
fizzbuzz()
{ std::cout << 0 << std::endl; }
};
template <int n>
struct fb_run
{
fizzbuzz<n, n%3, n%5> fb;
};
int main()
{
fb_run<100> fb;
return 0;
}

View file

@ -0,0 +1,164 @@
#include <iostream>
#include <string>
#include <cstdlib>
#include <boost/mpl/string.hpp>
#include <boost/mpl/fold.hpp>
#include <boost/mpl/size_t.hpp>
using namespace std;
using namespace boost;
///////////////////////////////////////////////////////////////////////////////
// exponentiation calculations
template <int accum, int base, int exp> struct POWER_CORE : POWER_CORE<accum * base, base, exp - 1>{};
template <int accum, int base>
struct POWER_CORE<accum, base, 0>
{
enum : int { val = accum };
};
template <int base, int exp> struct POWER : POWER_CORE<1, base, exp>{};
///////////////////////////////////////////////////////////////////////////////
// # of digit calculations
template <int depth, unsigned int i> struct NUM_DIGITS_CORE : NUM_DIGITS_CORE<depth + 1, i / 10>{};
template <int depth>
struct NUM_DIGITS_CORE<depth, 0>
{
enum : int { val = depth};
};
template <int i> struct NUM_DIGITS : NUM_DIGITS_CORE<0, i>{};
template <>
struct NUM_DIGITS<0>
{
enum : int { val = 1 };
};
///////////////////////////////////////////////////////////////////////////////
// Convert digit to character (1 -> '1')
template <int i>
struct DIGIT_TO_CHAR
{
enum : char{ val = i + 48 };
};
///////////////////////////////////////////////////////////////////////////////
// Find the digit at a given offset into a number of the form 0000000017
template <unsigned int i, int place> // place -> [0 .. 10]
struct DIGIT_AT
{
enum : char{ val = (i / POWER<10, place>::val) % 10 };
};
struct NULL_CHAR
{
enum : char{ val = '\0' };
};
///////////////////////////////////////////////////////////////////////////////
// Convert the digit at a given offset into a number of the form '0000000017' to a character
template <unsigned int i, int place> // place -> [0 .. 9]
struct ALT_CHAR : DIGIT_TO_CHAR< DIGIT_AT<i, place>::val >{};
///////////////////////////////////////////////////////////////////////////////
// Convert the digit at a given offset into a number of the form '17' to a character
// Template description, with specialization to generate null characters for out of range offsets
template <unsigned int i, int offset, int numDigits, bool inRange>
struct OFFSET_CHAR_CORE_CHECKED{};
template <unsigned int i, int offset, int numDigits>
struct OFFSET_CHAR_CORE_CHECKED<i, offset, numDigits, false> : NULL_CHAR{};
template <unsigned int i, int offset, int numDigits>
struct OFFSET_CHAR_CORE_CHECKED<i, offset, numDigits, true> : ALT_CHAR<i, (numDigits - offset) - 1 >{};
// Perform the range check and pass it on
template <unsigned int i, int offset, int numDigits>
struct OFFSET_CHAR_CORE : OFFSET_CHAR_CORE_CHECKED<i, offset, numDigits, offset < numDigits>{};
// Calc the number of digits and pass it on
template <unsigned int i, int offset>
struct OFFSET_CHAR : OFFSET_CHAR_CORE<i, offset, NUM_DIGITS<i>::val>{};
///////////////////////////////////////////////////////////////////////////////
// Integer to char* template. Works on unsigned ints.
template <unsigned int i>
struct IntToStr
{
const static char str[];
typedef typename mpl::string<
OFFSET_CHAR<i, 0>::val,
OFFSET_CHAR<i, 1>::val,
OFFSET_CHAR<i, 2>::val,
OFFSET_CHAR<i, 3>::val,
OFFSET_CHAR<i, 4>::val,
OFFSET_CHAR<i, 5>::val,
/*OFFSET_CHAR<i, 6>::val,
OFFSET_CHAR<i, 7>::val,
OFFSET_CHAR<i, 8>::val,
OFFSET_CHAR<i, 9>::val,*/
NULL_CHAR::val>::type type;
};
template <unsigned int i>
const char IntToStr<i>::str[] =
{
OFFSET_CHAR<i, 0>::val,
OFFSET_CHAR<i, 1>::val,
OFFSET_CHAR<i, 2>::val,
OFFSET_CHAR<i, 3>::val,
OFFSET_CHAR<i, 4>::val,
OFFSET_CHAR<i, 5>::val,
OFFSET_CHAR<i, 6>::val,
OFFSET_CHAR<i, 7>::val,
OFFSET_CHAR<i, 8>::val,
OFFSET_CHAR<i, 9>::val,
NULL_CHAR::val
};
template <bool condition, class Then, class Else>
struct IF
{
typedef Then RET;
};
template <class Then, class Else>
struct IF<false, Then, Else>
{
typedef Else RET;
};
template < typename Str1, typename Str2 >
struct concat : mpl::insert_range<Str1, typename mpl::end<Str1>::type, Str2> {};
template <typename Str1, typename Str2, typename Str3 >
struct concat3 : mpl::insert_range<Str1, typename mpl::end<Str1>::type, typename concat<Str2, Str3 >::type > {};
typedef typename mpl::string<'f','i','z','z'>::type fizz;
typedef typename mpl::string<'b','u','z','z'>::type buzz;
typedef typename mpl::string<'\r', '\n'>::type mpendl;
typedef typename concat<fizz, buzz>::type fizzbuzz;
// discovered boost mpl limitation on some length
template <int N>
struct FizzBuzz
{
typedef typename concat3<typename FizzBuzz<N - 1>::type, typename IF<N % 15 == 0, typename fizzbuzz::type, typename IF<N % 3 == 0, typename fizz::type, typename IF<N % 5 == 0, typename buzz::type, typename IntToStr<N>::type >::RET >::RET >::RET, typename mpendl::type>::type type;
};
template <>
struct FizzBuzz<1>
{
typedef mpl::string<'1','\r','\n'>::type type;
};
int main(int argc, char** argv)
{
const int n = 7;
std::cout << mpl::c_str<FizzBuzz<n>::type>::value << std::endl;
return 0;
}

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,33 @@
class Program
{
public void FizzBuzzGo()
{
Boolean Fizz = false;
Boolean Buzz = false;
for (int count = 1; count <= 100; count ++)
{
Fizz = count % 3 == 0;
Buzz = count % 5 == 0;
if (Fizz && Buzz)
{
Console.WriteLine("Fizz Buzz");
listBox1.Items.Add("Fizz Buzz");
}
else if (Fizz)
{
Console.WriteLine("Fizz");
listBox1.Items.Add("Fizz");
}
else if (Buzz)
{
Console.WriteLine("Buzz");
listBox1.Items.Add("Buzz");
}
else
{
Console.WriteLine(count);
listBox1.Items.Add(count);
}
}
}
}

View file

@ -0,0 +1,6 @@
using System;
int max = 100;
for(int i=0;
++i<=max;
Console.WriteLine("{0}{1}{2}", i%3==0 ? "Fizz" : "", i%5==0 ? "Buzz" : "", i%3!=0 && i%5!=0 ? i.ToString() : "")
){}

View file

@ -0,0 +1,18 @@
class Program
{
static void Main()
{
for (uint i = 1; i <= 100; i++)
{
string s = null;
if (i % 3 == 0)
s = "Fizz";
if (i % 5 == 0)
s += "Buzz";
System.Console.WriteLine(s ?? i.ToString());
}
}
}

View file

@ -0,0 +1,17 @@
using System;
using System.Linq;
namespace FizzBuzz
{
class Program
{
static void Main(string[] args)
{
Enumerable.Range(1, 100)
.Select(a => String.Format("{0}{1}", a % 3 == 0 ? "Fizz" : string.Empty, a % 5 == 0 ? "Buzz" : string.Empty))
.Select((b, i) => String.IsNullOrEmpty(b) ? (i + 1).ToString() : b)
.ToList()
.ForEach(Console.WriteLine);
}
}
}

View file

@ -0,0 +1,23 @@
using System;
using System.Globalization;
using System.Linq;
namespace FizzBuzz
{
class Program
{
static void Main()
{
Enumerable.Range(1, 100)
.GroupBy(e => e % 15 == 0 ? "FizzBuzz" : e % 5 == 0 ? "Buzz" : e % 3 == 0 ? "Fizz" : string.Empty)
.SelectMany(item => item.Select(x => new {
Value = x,
Display = String.IsNullOrEmpty(item.Key) ? x.ToString(CultureInfo.InvariantCulture) : item.Key
}))
.OrderBy(x => x.Value)
.Select(x => x.Display)
.ToList()
.ForEach(Console.WriteLine);
}
}
}

View file

@ -0,0 +1,29 @@
using System;
namespace FizzBuzz
{
class Program
{
static void Main(string[] args)
{
for (int i = 1; i <= 100; i++)
{
if (i % 15 == 0)
{
Console.WriteLine("FizzBuzz");
}
else if (i % 3 == 0)
{
Console.WriteLine("Fizz");
}
else if (i % 5 == 0)
{
Console.WriteLine("Buzz");
}
else
{
Console.WriteLine(i);
}
}
}
}
}

View file

@ -0,0 +1,30 @@
using System;
using System.Globalization;
namespace Rosettacode
{
class Program
{
static void Main()
{
for (var number = 0; number < 100; number++)
{
if ((number % 3) == 0 & (number % 5) == 0)
{
//For numbers which are multiples of both three and five print "FizzBuzz".
Console.WriteLine("FizzBuzz");
continue;
}
if ((number % 3) == 0) Console.WriteLine("Fizz");
if ((number % 5) == 0) Console.WriteLine("Buzz");
if ((number % 3) != 0 && (number % 5) != 0) Console.WriteLine(number.ToString(CultureInfo.InvariantCulture));
if (number % 5 == 0)
{
Console.WriteLine(Environment.NewLine);
}
}
}
}
}

View file

@ -0,0 +1,13 @@
using System;
using System.Linq;
namespace FizzBuzz
{
class Program
{
static void Main(string[] args)
{
Enumerable.Range(1, 100).ToList().ForEach(i => Console.WriteLine(i % 5 == 0 ? string.Format(i % 3 == 0 ? "Fizz{0}" : "{0}", "Buzz") : string.Format(i%3 == 0 ? "Fizz" : i.ToString())));
}
}
}

View file

@ -0,0 +1,19 @@
class Program
{
public static string FizzBuzzIt(int n) =>
(n % 3, n % 5) switch
{
(0, 0) => "FizzBuzz",
(0, _) => "Fizz",
(_, 0) => "Buzz",
(_, _) => $"{n}"
};
static void Main(string[] args)
{
foreach (var n in Enumerable.Range(1, 100))
{
Console.WriteLine(FizzBuzzIt(n));
}
}
}

View file

@ -0,0 +1,83 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace FizzBuzz
{
[TestClass]
public class FizzBuzzTest
{
private FizzBuzz fizzBuzzer;
[TestInitialize]
public void Initialize()
{
fizzBuzzer = new FizzBuzz();
}
[TestMethod]
public void Give4WillReturn4()
{
Assert.AreEqual("4", fizzBuzzer.FizzBuzzer(4));
}
[TestMethod]
public void Give9WillReturnFizz()
{
Assert.AreEqual("Fizz", fizzBuzzer.FizzBuzzer(9));
}
[TestMethod]
public void Give25WillReturnBuzz()
{
Assert.AreEqual("Buzz", fizzBuzzer.FizzBuzzer(25));
}
[TestMethod]
public void Give30WillReturnFizzBuzz()
{
Assert.AreEqual("FizzBuzz", fizzBuzzer.FizzBuzzer(30));
}
[TestMethod]
public void First15()
{
ICollection expected = new ArrayList
{"1", "2", "Fizz", "4", "Buzz", "Fizz", "7", "8", "Fizz", "Buzz", "11", "Fizz", "13", "14", "FizzBuzz"};
var actual = Enumerable.Range(1, 15).Select(x => fizzBuzzer.FizzBuzzer(x)).ToList();
CollectionAssert.AreEqual(expected, actual);
}
[TestMethod]
public void From1To100_ToShowHowToGet100()
{
const int expected = 100;
var actual = Enumerable.Range(1, 100).Select(x => fizzBuzzer.FizzBuzzer(x)).ToList();
Assert.AreEqual(expected, actual.Count);
}
}
public class FizzBuzz
{
private delegate string Xzzer(int value);
private readonly IList<Xzzer> _functions = new List<Xzzer>();
public FizzBuzz()
{
_functions.Add(x => x % 3 == 0 ? "Fizz" : "");
_functions.Add(x => x % 5 == 0 ? "Buzz" : "");
}
public string FizzBuzzer(int value)
{
var result = _functions.Aggregate(String.Empty, (current, function) => current + function.Invoke(value));
return String.IsNullOrEmpty(result) ? value.ToString(CultureInfo.InvariantCulture) : result;
}
}
}

View file

@ -0,0 +1,4 @@
int i = 0 ; char B[88] ;
while ( i++ < 100 )
!sprintf( B, "%s%s", i%3 ? "":"Fizz", i%5 ? "":"Buzz" )
? sprintf( B, "%d", i ):0, printf( ", %s", B );

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,5 @@
int i = 0 ; char B[88] ;
while ( i++ < 100 )
!sprintf( B, "%s%s%s%s",
i%3 ? "":"Fiz", i%5 ? "":"Buz", i%7 ? "":"Goz", i%11 ? "":"Kaz" )
? sprintf( B, "%d", i ):0, printf( ", %s", B );

View file

@ -0,0 +1 @@
Output: ..., 89, FizBuz, Goz, 92, Fiz, 94, Buz, Fiz, 97, Goz, FizKaz, Buz

View file

@ -0,0 +1,5 @@
#include <stdio.h>
int main() {
for (int i=1; i<=105; i++) if (i%3 && i%5) printf("%3d ", i); else printf("%s%s%s", i%3?"":"Fizz", i%5?"":"Buzz", i%15?" ":"\n");
}

View file

@ -0,0 +1,10 @@
#include<stdio.h>
int main ()
{
int i;
const char *s[] = { "%d\n", "Fizz\n", s[3] + 4, "FizzBuzz\n" };
for (i = 1; i <= 100; i++)
printf(s[!(i % 3) + 2 * !(i % 5)], i);
return 0;
}

View file

@ -0,0 +1,20 @@
#include<stdio.h>
int main (void)
{
int i;
for (i = 1; i <= 100; i++)
{
if (!(i % 15))
printf ("FizzBuzz");
else if (!(i % 3))
printf ("Fizz");
else if (!(i % 5))
printf ("Buzz");
else
printf ("%d", i);
printf("\n");
}
return 0;
}

View file

@ -0,0 +1,16 @@
#include <stdio.h>
main() {
int i = 1;
while(i <= 100) {
if(i % 15 == 0)
puts("FizzBuzz");
else if(i % 3 == 0)
puts("Fizz");
else if(i % 5 == 0)
puts("Buzz");
else
printf("%d\n", i);
i++;
}
}

View file

@ -0,0 +1,3 @@
#include <stdio.h>
#define F(x,y) printf("%s",i%x?"":#y"zz")
int main(int i){for(--i;i++^100;puts(""))F(3,Fi)|F(5,Bu)||printf("%i",i);return 0;}

View file

@ -0,0 +1,11 @@
#include <stdio.h>
int main(void)
{
for (int i = 1; i <= 100; ++i) {
if (i % 3 == 0) printf("fizz");
if (i % 5 == 0) printf("buzz");
if (i * i * i * i % 15 == 1) printf("%d", i);
puts("");
}
}

View file

@ -0,0 +1,26 @@
(deffacts count
(count-to 100)
)
(defrule print-numbers
(count-to ?max)
=>
(loop-for-count (?num ?max) do
(if
(= (mod ?num 3) 0)
then
(printout t "Fizz")
)
(if
(= (mod ?num 5) 0)
then
(printout t "Buzz")
)
(if
(and (> (mod ?num 3) 0) (> (mod ?num 5) 0))
then
(printout t ?num)
)
(priint depth, unsigned int i> struct NUM_DIGITS_CORE : NUM_DIGITS_COREntout t crlf)
)
)

View file

@ -0,0 +1,11 @@
start_up = proc ()
po: stream := stream$primary_output()
for i: int in int$from_to(1, 100) do
out: string := ""
if i // 3 = 0 then out := out || "Fizz" end
if i // 5 = 0 then out := out || "Buzz" end
if string$empty(out) then out := int$unparse(i) end
stream$putl(po, out)
end
end start_up

View file

@ -0,0 +1,13 @@
foreach(i RANGE 1 100)
math(EXPR off3 "${i} % 3")
math(EXPR off5 "${i} % 5")
if(NOT off3 AND NOT off5)
message(FizzBuzz)
elseif(NOT off3)
message(Fizz)
elseif(NOT off5)
message(Buzz)
else()
message(${i})
endif()
endforeach(i)

View file

@ -0,0 +1,36 @@
* FIZZBUZZ.COB
* cobc -x -g FIZZBUZZ.COB
*
IDENTIFICATION DIVISION.
PROGRAM-ID. fizzbuzz.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 CNT PIC 9(03) VALUE 1.
01 REM PIC 9(03) VALUE 0.
01 QUOTIENT PIC 9(03) VALUE 0.
PROCEDURE DIVISION.
*
PERFORM UNTIL CNT > 100
DIVIDE 15 INTO CNT GIVING QUOTIENT REMAINDER REM
IF REM = 0
THEN
DISPLAY "FizzBuzz " WITH NO ADVANCING
ELSE
DIVIDE 3 INTO CNT GIVING QUOTIENT REMAINDER REM
IF REM = 0
THEN
DISPLAY "Fizz " WITH NO ADVANCING
ELSE
DIVIDE 5 INTO CNT GIVING QUOTIENT REMAINDER REM
IF REM = 0
THEN
DISPLAY "Buzz " WITH NO ADVANCING
ELSE
DISPLAY CNT " " WITH NO ADVANCING
END-IF
END-IF
END-IF
ADD 1 TO CNT
END-PERFORM
DISPLAY ""
STOP RUN.

View file

@ -0,0 +1,16 @@
Identification division.
Program-id. fizz-buzz.
Data division.
Working-storage section.
01 num pic 999.
Procedure division.
Perform varying num from 1 by 1 until num > 100
if function mod (num, 15) = 0 then display "fizzbuzz"
else if function mod (num, 3) = 0 then display "fizz"
else if function mod (num, 5) = 0 then display "buzz"
else display num
end-perform.
Stop run.

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

@ -0,0 +1,29 @@
>>SOURCE FORMAT FREE
identification division.
program-id. fizzbuzz.
data division.
working-storage section.
01 i pic 999.
01 fizz pic 999 value 3.
01 buzz pic 999 value 5.
procedure division.
start-fizzbuzz.
perform varying i from 1 by 1 until i > 100
evaluate i also i
when fizz also buzz
display 'fizzbuzz'
add 3 to fizz
add 5 to buzz
when fizz also any
display 'fizz'
add 3 to fizz
when buzz also any
display 'buzz'
add 5 to buzz
when other
display i
end-evaluate
end-perform
stop run
.
end program fizzbuzz.

View file

@ -0,0 +1,18 @@
(* FizzBuzz in CDuce *)
let format (n : Int) : Latin1 =
if (n mod 3 = 0) || (n mod 5 = 0) then "FizzBuzz"
else if (n mod 5 = 0) then "Buzz"
else if (n mod 3 = 0) then "Fizz"
else string_of (n);;
let fizz (n : Int, size : Int) : _ =
print (format (n) @ "\n");
if (n = size) then
n = 0 (* do nothing *)
else
fizz(n + 1, size);;
let fizbuzz (size : Int) : _ = fizz (1, size);;
let _ = fizbuzz(100);;

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,13 @@
proc fizzbuzz(n) {
for i in 1..n do
if i % 15 == 0 then
writeln("FizzBuzz");
else if i % 5 == 0 then
writeln("Buzz");
else if i % 3 == 0 then
writeln("Fizz");
else
writeln(i);
}
fizzbuzz(100);

View file

@ -0,0 +1,8 @@
main() {
for(i in range(1,100)) {
if(i % 3 == 0 and i % 5 == 0) println("fizzbuzz");
else if(i % 3 == 0) println("fizz");
else if(i % 5 == 0) println("buzz");
else print(i);
}
}

View file

@ -0,0 +1,12 @@
PROCEDURE Main()
LOCAL n
LOCAL cFB
FOR n := 1 TO 100
cFB := ""
AEval( { { 3, "Fizz" }, { 5, "Buzz" } }, {|x| cFB += iif( ( n % x[ 1 ] ) == 0, x[ 2 ], "" ) } )
?? iif( cFB == "", LTrim( Str( n ) ), cFB ) + iif( n == 100, ".", ", " )
NEXT
RETURN

View file

@ -0,0 +1 @@
(doseq [x (range 1 101)] (println x (str (when (zero? (mod x 3)) "fizz") (when (zero? (mod x 5)) "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

@ -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,19 @@
;;Using clojure maps
(defn fizzbuzz
[n]
(let [rule {3 "Fizz"
5 "Buzz"}
divs (->> rule
(map first)
sort
(filter (comp (partial = 0)
(partial rem n))))]
(if (empty? divs)
(str n)
(->> divs
(map rule)
(apply str)))))
(defn allfizzbuzz
[max]
(map fizzbuzz (range 1 (inc max))))

Some files were not shown because too many files have changed in this diff Show more