September Morn Update

This commit is contained in:
Ingy döt Net 2019-09-12 10:33:56 -07:00
parent 4e2d22a71d
commit aac6731f2c
6856 changed files with 141342 additions and 21127 deletions

View file

@ -1 +1,4 @@
for(i=0;i<100;console.log((++i%3?"":"Fizz")+(i%5?"":"Buzz")||i));
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

@ -1,11 +1,10 @@
#include <stdio.h>
int main(void)
int main()
{
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("");
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

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

@ -1,5 +1 @@
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 );
Output: ..., 89, FizBuz, Goz, 92, Fiz, 94, Buz, Fiz, 97, Goz, FizKaz, Buz

View file

@ -1 +1,5 @@
Output: ..., 89, FizBuz, Goz, 92, Fiz, 94, Buz, Fiz, 97, Goz, FizKaz, Buz
#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

@ -1,5 +1,10 @@
#include <stdio.h>
#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");
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

@ -1,11 +1,20 @@
#include<stdio.h>
int main ()
int main (void)
{
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);
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);
return 0;
printf("\n");
}
return 0;
}

View file

@ -1,20 +1,16 @@
#include<stdio.h>
#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;
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

@ -1,16 +1,3 @@
#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++;
}
}
#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

@ -1,3 +1,11 @@
#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;}
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,17 @@
import std;
void main()
{
auto fizzbuzz(in uint i)
{
string r;
if (i % 3 == 0) r ~= "fizz";
if (i % 5 == 0) r ~= "buzz";
if (r.length == 0) r ~= i.to!string;
return r;
}
enum r = 1.iota(101).map!fizzbuzz;
r.each!writeln;
}

View file

@ -1,8 +1,8 @@
import Graphics.Element exposing (show)
import Html exposing (text)
import List exposing (map)
main =
map getWordForNum [1..100] |> show
[1..100] |> map getWordForNum |> text
getWordForNum num =
if num % 15 == 0 then
@ -12,4 +12,4 @@ getWordForNum num =
else if num % 5 == 0 then
"Buzz"
else
toString num
String.fromInt num

View file

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

View file

@ -12,7 +12,8 @@ IN: fizzbuzz
: fizz ( str n -- str n ) dup 3 < [ 1 + ] [ drop "Fizz" append 1 ] if ;
: buzz ( str n -- str n ) dup 5 < [ 1 + ] [ drop "Buzz" append 1 ] if ;
: FizzBuzz ( m -- v ) { fizz buzz } zz ;
: FizzBuzz-100 ( -- ) 100 FizzBuzz . ;
: quxx ( str n -- str n ) dup 7 < [ 1 + ] [ drop "Quxx" append 1 ] if ;
: FizzBuzzQuxx ( m -- v ) { fizz buzz quxx } zz ;
: FizzBuzzQuxx-100 ( -- ) 100 FizzBuzzQuxx . ;
MAIN: FizzBuzz-100
MAIN: FizzBuzzQuxx-100

View file

@ -0,0 +1,11 @@
package main
import "fmt"
func main() {
for i := 1; i <= 100; i++ {
fmt.Println(map[bool]map[bool]interface{}{
false: {false: i, true: "Fizz"}, true: {false: "Buzz", true: "FizzBuzz"},
}[i%5 == 0][i%3 == 0])
}
}

View file

@ -0,0 +1,7 @@
fizzbuzz n = case (rem n 3, rem n 5) of
(0, 0) -> "FizzBuzz"
(0, _) -> "Fizz"
(_, 0) -> "Buzz"
(_, _) -> show n
main = mapM_ (putStrLn . fizzbuzz) [1..100]

View file

@ -1,12 +1,15 @@
import Control.Monad.State
import Control.Monad.Trans
import Control.Monad.Writer
import Data.List (zipWith3)
import Data.Bool (bool)
main = putStr $ execWriter $ mapM_ (flip execStateT True . fizzbuzz) [1..100]
fizzBuzz :: [String]
fizzBuzz =
zipWith3
(\f b n ->
let fb = f ++ b
in bool fb n (null fb))
(cycle $ replicate 2 [] ++ ["fizz"])
(cycle $ replicate 4 [] ++ ["buzz"])
(show <$> [1 ..])
fizzbuzz :: Int -> StateT Bool (Writer String) ()
fizzbuzz x = do
when (x `mod` 3 == 0) $ tell "Fizz" >> put False
when (x `mod` 5 == 0) $ tell "Buzz" >> put False
get >>= (flip when $ tell $ show x)
tell "\n"
main :: IO ()
main = mapM_ putStrLn $ take 100 fizzBuzz

View file

@ -1,10 +1,12 @@
fizzBuzz :: (Integral a) => a -> String
fizzBuzz i
| fizz && buzz = "FizzBuzz"
| fizz = "Fizz"
| buzz = "Buzz"
| otherwise = show i
where fizz = i `mod` 3 == 0
buzz = i `mod` 5 == 0
import Data.Bool (bool)
main = mapM_ (putStrLn . fizzBuzz) [1..100]
fizzBuzz :: [String]
fizzBuzz =
let fb n k = cycle (replicate (pred n) [] ++ [k])
in zipWith
(flip . bool <*> null)
(zipWith (++) (fb 3 "fizz") (fb 5 "buzz"))
(show <$> [1 ..])
main :: IO ()
main = mapM_ putStrLn $ take 100 fizzBuzz

View file

@ -1,12 +1,12 @@
import Data.Monoid
import Control.Monad.State
import Control.Monad.Trans
import Control.Monad.Writer
fizzbuzz = max
<$> show
<*> "fizz" `when` divisibleBy 3
<> "buzz" `when` divisibleBy 5
<> "quxx" `when` divisibleBy 7
where
when m p x = if p x then m else mempty
divisibleBy n x = x `mod` n == 0
main = putStr $ execWriter $ mapM_ (flip execStateT True . fizzbuzz) [1..100]
main = mapM_ (putStrLn . fizzbuzz) [1..100]
fizzbuzz :: Int -> StateT Bool (Writer String) ()
fizzbuzz x = do
when (x `mod` 3 == 0) $ tell "Fizz" >> put False
when (x `mod` 5 == 0) $ tell "Buzz" >> put False
get >>= (flip when $ tell $ show x)
tell "\n"

View file

@ -0,0 +1,10 @@
fizzBuzz :: (Integral a) => a -> String
fizzBuzz i
| fizz && buzz = "FizzBuzz"
| fizz = "Fizz"
| buzz = "Buzz"
| otherwise = show i
where fizz = i `mod` 3 == 0
buzz = i `mod` 5 == 0
main = mapM_ (putStrLn . fizzBuzz) [1..100]

View file

@ -0,0 +1,12 @@
import Data.Monoid
fizzbuzz = max
<$> show
<*> "fizz" `when` divisibleBy 3
<> "buzz" `when` divisibleBy 5
<> "quxx" `when` divisibleBy 7
where
when m p x = if p x then m else mempty
divisibleBy n x = x `mod` n == 0
main = mapM_ (putStrLn . fizzbuzz) [1..100]

View file

@ -0,0 +1,17 @@
class FizzBuzz {
public static void main(String[] args) {
for (int i = 1; i < 101; i++) {
if ((i % 3 == 0) && (i % 5 == 0)) {
System.out.print("'fizz buzz', ");
} else if (i % 3 == 0) {
System.out.print("'fizz', ");
} else if (i % 5 == 0) {
System.out.print("'buzz', ");
} else {
System.out.printf("%d, ", i);
}
}
}
}

View file

@ -0,0 +1,6 @@
const factors = [[3, 'Fizz'], [5, 'Buzz']]
const fizzBuzz = num => factors.map(([factor,text]) => (num % factor)?'':text).join('') || num
const range1 = x => [...Array(x+1).keys()].slice(1)
const outputs = range1(100).map(fizzBuzz)
console.log(outputs.join('\n'))

View file

@ -0,0 +1,185 @@
(() => {
'use strict';
// main :: IO ()
const main = () => {
// FIZZBUZZ ---------------------------------------
// fizzBuzz :: Generator [String]
const fizzBuzz = () => {
const fb = n => k => cycle(
replicate(n - 1)('').concat(k)
);
return zipWith(
liftA2(flip)(bool)(isNull)
)(
zipWith(append)(fb(3)('fizz'))(fb(5)('buzz'))
)(fmap(str)(enumFrom(1)));
};
// TEST -------------------------------------------
console.log(
unlines(
take(100)(
fizzBuzz()
)
)
);
};
// GENERIC FUNCTIONS ----------------------------------
// Just :: a -> Maybe a
const Just = x => ({
type: 'Maybe',
Nothing: false,
Just: x
});
// Nothing :: Maybe a
const Nothing = () => ({
type: 'Maybe',
Nothing: true,
});
// Tuple (,) :: a -> b -> (a, b)
const Tuple = a => b => ({
type: 'Tuple',
'0': a,
'1': b,
length: 2
});
// append (++) :: [a] -> [a] -> [a]
// append (++) :: String -> String -> String
const append = xs => ys => xs.concat(ys);
// bool :: a -> a -> Bool -> a
const bool = f => t => p =>
p ? t : f;
// cycle :: [a] -> Generator [a]
function* cycle(xs) {
const lng = xs.length;
let i = 0;
while (true) {
yield(xs[i])
i = (1 + i) % lng;
}
}
// enumFrom :: Int => Int -> [Int]
function* enumFrom(x) {
let v = x;
while (true) {
yield v;
v = 1 + v;
}
}
// flip :: (a -> b -> c) -> b -> a -> c
const flip = f =>
x => y => f(y)(x);
// fmap <$> :: (a -> b) -> Gen [a] -> Gen [b]
const fmap = f =>
function*(gen) {
let v = take(1)(gen);
while (0 < v.length) {
yield(f(v[0]))
v = take(1)(gen)
}
};
// fst :: (a, b) -> a
const fst = tpl => tpl[0];
// isNull :: [a] -> Bool
// isNull :: String -> Bool
const isNull = xs =>
1 > xs.length;
// Returns Infinity over objects without finite length.
// This enables zip and zipWith to choose the shorter
// argument when one is non-finite, like cycle, repeat etc
// length :: [a] -> Int
const length = xs =>
(Array.isArray(xs) || 'string' === typeof xs) ? (
xs.length
) : Infinity;
// liftA2 :: (a0 -> b -> c) -> (a -> a0) -> (a -> b) -> a -> c
const liftA2 = op => f => g =>
// Lift a binary function to a composition
// over two other functions.
// liftA2 (*) (+ 2) (+ 3) 7 == 90
x => op(f(x))(g(x));
// replicate :: Int -> a -> [a]
const replicate = n => x =>
Array.from({
length: n
}, () => x);
// snd :: (a, b) -> b
const snd = tpl => tpl[1];
// str :: a -> String
const str = x => x.toString();
// take :: Int -> [a] -> [a]
// take :: Int -> String -> String
const take = n => xs =>
'GeneratorFunction' !== xs.constructor.constructor.name ? (
xs.slice(0, n)
) : [].concat.apply([], Array.from({
length: n
}, () => {
const x = xs.next();
return x.done ? [] : [x.value];
}));
// The first argument is a sample of the type
// allowing the function to make the right mapping
// uncons :: [a] -> Maybe (a, [a])
const uncons = xs => {
const lng = length(xs);
return (0 < lng) ? (
lng < Infinity ? (
Just(Tuple(xs[0])(xs.slice(1))) // Finite list
) : (() => {
const nxt = take(1)(xs);
return 0 < nxt.length ? (
Just(Tuple(nxt[0])(xs))
) : Nothing();
})() // Lazy generator
) : Nothing();
};
// unlines :: [String] -> String
const unlines = xs => xs.join('\n');
// zipWith :: (a -> b -> c) Gen [a] -> Gen [b] -> Gen [c]
const zipWith = f => ga => gb => {
function* go(ma, mb) {
let
a = ma,
b = mb;
while (!a.Nothing && !b.Nothing) {
let
ta = a.Just,
tb = b.Just
yield(f(fst(ta))(fst(tb)));
a = uncons(snd(ta));
b = uncons(snd(tb));
}
}
return go(uncons(ga), uncons(gb));
};
// MAIN ---
return main();
})();

View file

@ -0,0 +1,3 @@
fun fizzBuzz() {
println((1..100).map{i->mapOf(0 to i,i%3 to "Fizz",i%5 to "Buzz",i%15 to "FizzBuzz")[0]})
}

View file

@ -0,0 +1,101 @@
; ModuleID = 'fizzbuzz.c'
; source_filename = "fizzbuzz.c"
; target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
; target triple = "x86_64-pc-windows-msvc19.21.27702"
; This is not strictly LLVM, as it uses the C library function "printf".
; LLVM does not provide a way to print values, so the alternative would be
; to just load the string into memory, and that would be boring.
; Additional comments have been inserted, as well as changes made from the output produced by clang such as putting more meaningful labels for the jumps
$"\01??_C@_09NODAFEIA@FizzBuzz?6?$AA@" = comdat any
$"\01??_C@_05KEBFOHOF@Fizz?6?$AA@" = comdat any
$"\01??_C@_05JKJENPHA@Buzz?6?$AA@" = comdat any
$"\01??_C@_03PMGGPEJJ@?$CFd?6?$AA@" = comdat any
;--- String constant defintions
@"\01??_C@_09NODAFEIA@FizzBuzz?6?$AA@" = linkonce_odr unnamed_addr constant [10 x i8] c"FizzBuzz\0A\00", comdat, align 1
@"\01??_C@_05KEBFOHOF@Fizz?6?$AA@" = linkonce_odr unnamed_addr constant [6 x i8] c"Fizz\0A\00", comdat, align 1
@"\01??_C@_05JKJENPHA@Buzz?6?$AA@" = linkonce_odr unnamed_addr constant [6 x i8] c"Buzz\0A\00", comdat, align 1
@"\01??_C@_03PMGGPEJJ@?$CFd?6?$AA@" = linkonce_odr unnamed_addr constant [4 x i8] c"%d\0A\00", comdat, align 1
;--- The declaration for the external C printf function.
declare i32 @printf(i8*, ...)
; Function Attrs: noinline nounwind optnone uwtable
define i32 @main() #0 {
%1 = alloca i32, align 4
store i32 1, i32* %1, align 4
;--- It does not seem like this branch can be removed
br label %loop
;--- while (i <= 100)
loop:
%2 = load i32, i32* %1, align 4
%3 = icmp sle i32 %2, 100
br i1 %3, label %divisible_15, label %finished
;--- if (i % 15 == 0)
divisible_15:
%4 = load i32, i32* %1, align 4
%5 = srem i32 %4, 15
%6 = icmp eq i32 %5, 0
br i1 %6, label %print_fizzbuzz, label %divisible_3
;--- Print 'FizzBuzz'
print_fizzbuzz:
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @"\01??_C@_09NODAFEIA@FizzBuzz?6?$AA@", i32 0, i32 0))
br label %next
;--- if (i % 3 == 0)
divisible_3:
%8 = load i32, i32* %1, align 4
%9 = srem i32 %8, 3
%10 = icmp eq i32 %9, 0
br i1 %10, label %print_fizz, label %divisible_5
;--- Print 'Fizz'
print_fizz:
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @"\01??_C@_05KEBFOHOF@Fizz?6?$AA@", i32 0, i32 0))
br label %next
;--- if (i % 5 == 0)
divisible_5:
%12 = load i32, i32* %1, align 4
%13 = srem i32 %12, 5
%14 = icmp eq i32 %13, 0
br i1 %14, label %print_buzz, label %print_number
;--- Print 'Buzz'
print_buzz:
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @"\01??_C@_05JKJENPHA@Buzz?6?$AA@", i32 0, i32 0))
br label %next
;--- Print the number
print_number:
%16 = load i32, i32* %1, align 4
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @"\01??_C@_03PMGGPEJJ@?$CFd?6?$AA@", i32 0, i32 0), i32 %16)
;--- It does not seem like this branch can be removed
br label %next
;--- i = i + 1
next:
%18 = load i32, i32* %1, align 4
%19 = add nsw i32 %18, 1
store i32 %19, i32* %1, align 4
br label %loop
;--- exit main
finished:
ret i32 0
}
attributes #0 = { noinline nounwind optnone uwtable "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
!llvm.module.flags = !{!0, !1}
!llvm.ident = !{!2}
!0 = !{i32 1, !"wchar_size", i32 2}
!1 = !{i32 7, !"PIC Level", i32 2}
!2 = !{!"clang version 6.0.1 (tags/RELEASE_601/final)"}

View file

@ -0,0 +1,13 @@
local t = {
[0] = "FizzBuzz",
[3] = "Fizz",
[5] = "Buzz",
[6] = "Fizz",
[9] = "Fizz",
[10] = "Buzz",
[12] = "Fizz"
}
for i = 1, 100 do
print(t[i%15] or i)
end

View file

@ -1,13 +1,8 @@
:- module fizzbuzz.
:- interface.
:- import_module io.
:- pred main(io::di, io::uo) is det.
:- implementation.
:- import_module int, string, bool.
:- func fizz(int) = bool.
@ -27,6 +22,10 @@ main(!IO) :- main(1, 100, !IO).
:- pred main(int::in, int::in, io::di, io::uo) is det.
main(N, To, !IO) :-
io.write_string(fizzbuzz(N, fizz(N), buzz(N)), !IO), io.nl(!IO),
( N < To -> main(N + 1, To, !IO)
; !:IO = !.IO ).
io.write_string(fizzbuzz(N, fizz(N), buzz(N)), !IO),
io.nl(!IO),
( if N < To then
main(N + 1, To, !IO)
else
true
).

View file

@ -7,17 +7,14 @@ MODULE FizzBuzz;
BEGIN
FOR i := 1 TO 100 DO
IF i MOD 15 = 0 THEN
Out.String("FizzBuzz");
Out.Ln;
Out.String("FizzBuzz")
ELSIF i MOD 5 = 0 THEN
Out.String("Buzz");
Out.Ln;
Out.String("Buzz")
ELSIF i MOD 3 = 0 THEN
Out.String("Fizz");
Out.Ln;
Out.String("Fizz")
ELSE
Out.Int(i,0);
Out.Ln;
Out.Int(i,0)
END;
END;
Out.Ln
END
END FizzBuzz.

View file

@ -0,0 +1 @@
for($i=0;$i++<100;)echo($i%3?'':'Fizz').($i%5?'':'Buzz')?:$i,"\n";

View file

@ -0,0 +1 @@
for($i = 0; $i++ < 100;) echo [$i, 'Fizz', 'Buzz', 'FizzBuzz'][!($i % 3) + 2 * !($i % 5)], "\n";

View file

@ -0,0 +1,6 @@
@FB1 = (1..100);
@FB2 = map{!($_%3 or $_%5)?'FizzBuzz': $_}@FB1;
@FB3 = map{(/\d/ and !($_%3))?'Fizz': $_}@FB2;
@FB4 = map{(/\d/ and !($_%5))?'Buzz': $_}@FB3;
@FB5 = map{$_."\n"}@FB4;
print @FB5;

View file

@ -1,14 +1 @@
filter fizz-buzz{
@(
$_,
"Fizz",
"Buzz",
"FizzBuzz"
)[
2 *
($_ -match '[05]$') +
($_ -match '(^([369][0369]?|[258][147]|[147][258]))$')
]
}
1..100 | fizz-buzz
1..100 | % {write-host("$(if(($_ % 3 -ne 0) -and ($_ % 5 -ne 0)){$_})$(if($_ % 3 -eq 0){"Fizz"})$(if($_ % 5 -eq 0){"Buzz"})")}

View file

@ -0,0 +1,14 @@
filter fizz-buzz{
@(
$_,
"Fizz",
"Buzz",
"FizzBuzz"
)[
2 *
($_ -match '[05]$') +
($_ -match '(^([369][0369]?|[258][147]|[147][258]))$')
]
}
1..100 | fizz-buzz

View file

@ -0,0 +1,11 @@
for(int i = 1; i <= 100; i++){
String output = "";
if(i % 3 == 0) output += "Fizz";
if(i % 5 == 0) output += "Buzz";
// copy & paste above line to add more tests
if(output == "") output = int(i);
println(output);
}
}

View file

@ -1,6 +1,4 @@
is-positive = _ > 0 # equivalent to lam(x): x > 0 end
fun fizzbuzz(n :: Number%(is-positive)) -> String:
fun fizzbuzz(n :: NumPositive) -> 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:

View file

@ -0,0 +1 @@
print(*map(lambda n: 'Fizzbuzz '[(i):i+13] if (i := n**4%-15) > -14 else n, range(1,100)))

View file

@ -1 +1,9 @@
for i in range(1,101): print("Fizz"*(i%3==0) + "Buzz"*(i%5==0) or i)
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)

View file

@ -1 +1 @@
for i in range(100):print(i%3//2*'Fizz'+i%5//4*'Buzz'or i+1)
for i in range(1,101): print("Fizz"*(i%3==0) + "Buzz"*(i%5==0) or i)

View file

@ -1,3 +1 @@
for n in range(1, 100):
fb = ''.join([ denom[1] if n % denom[0] == 0 else '' for denom in [(3,'fizz'),(5,'buzz')] ])
print fb if fb else n
for i in range(100):print(i%3//2*'Fizz'+i%5//4*'Buzz'or i+1)

View file

@ -1 +1,3 @@
[print("FizzBuzz") if i % 15 == 0 else print("Fizz") if i % 3 == 0 else print("Buzz") if i % 5 == 0 else print(i) for i in range(1,101)]
for n in range(1, 100):
fb = ''.join([ denom[1] if n % denom[0] == 0 else '' for denom in [(3,'fizz'),(5,'buzz')] ])
print fb if fb else n

View file

@ -1,13 +1 @@
from itertools import cycle, izip, count, islice
fizzes = cycle([""] * 2 + ["Fizz"])
buzzes = cycle([""] * 4 + ["Buzz"])
both = (f + b for f, b in izip(fizzes, buzzes))
# if the string is "", yield the number
# otherwise yield the string
fizzbuzz = (word or n for word, n in izip(both, count(1)))
# print the first 100
for i in islice(fizzbuzz, 100):
print i
print (', '.join([(x%3<1)*'Fizz'+(x%5<1)*'Buzz' or str(x) for x in range(1,101)]))

View file

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

View file

@ -0,0 +1,13 @@
from itertools import cycle, izip, count, islice
fizzes = cycle([""] * 2 + ["Fizz"])
buzzes = cycle([""] * 4 + ["Buzz"])
both = (f + b for f, b in izip(fizzes, buzzes))
# if the string is "", yield the number
# otherwise yield the string
fizzbuzz = (word or n for word, n in izip(both, count(1)))
# print the first 100
for i in islice(fizzbuzz, 100):
print i

View file

@ -0,0 +1,52 @@
'''Fizz buzz'''
from itertools import count, cycle, islice
# fizzBuzz :: () -> Generator [String]
def fizzBuzz():
'''A non-finite stream of fizzbuzz terms.'''
return map(
lambda f, b, n: (f + b) or n,
cycle([''] * 2 + ['Fizz']),
cycle([''] * 4 + ['Buzz']),
map(str, count(1))
)
# main :: IO ()
def main():
'''Display of first 100 terms of the fizzbuzz series.
'''
print(unlines(
take(100)(
fizzBuzz()
)
))
# GENERIC -------------------------------------------------
# take :: Int -> [a] -> [a]
# take :: Int -> String -> String
def take(n):
'''The prefix of xs of length n,
or xs itself if n > length xs.
'''
return lambda xs: (
xs[0:n]
if isinstance(xs, (list, tuple))
else list(islice(xs, n))
)
# unlines :: [String] -> String
def unlines(xs):
'''A single string formed by the intercalation
of a list of strings with the newline character.
'''
return '\n'.join(xs)
if __name__ == '__main__':
main()

View file

@ -1,3 +1,5 @@
#lang racket
(for ([n (in-range 1 101)])
(displayln
(match (gcd n 15)

View file

@ -0,0 +1,26 @@
set "local1" to 1
: "loop"
wait for 10
if "('local1' % 15)" = 0 then "fizzbuzz"
if "('local1' % 3)" = 0 then "fizz"
if "('local1' % 5)" = 0 then "buzz"
* "&local1&"
: "inc"
inc "local1" by 1
if "local1" <= 100 then "loop"
goto "done"
: "fizzbuzz"
* "FizzBuzz"
goto "inc"
: "fizz"
* "Fizz"
goto "inc"
: "buzz"
* "Buzz"
goto "inc"
: "done"
end

View file

@ -0,0 +1,29 @@
(defprolog fizz
0 <-- (is _ (output "Fizz"));
N <-- (when (> N 0)) (is N1 (- N 3)) (fizz N1);
)
(defprolog buzz
0 <-- (is _ (output "Buzz"));
N <-- (when (> N 0)) (is N1 (- N 5)) (buzz N1);
)
(define none
[] -> true
[true | _] -> false
[_ | B] -> (none B)
)
(define fizzbuzz
N M -> (nl) where (> N M)
N M -> (do
(if (none [(prolog? (receive N) (fizz N)) (prolog? (receive N) (buzz N))])
(output (str N))
(output "!")
)
(nl)
(fizzbuzz (+ N 1) M)
)
)
(fizzbuzz 1 100)

View file

@ -1,11 +1,13 @@
for n in `seq 1 100`; do
if [ $((n % 15)) = 0 ]; then
n=1
while [ 100 -ge n ]; do
if [ $((n % 15)) -eq 0 ]; then
echo FizzBuzz
elif [ $((n % 3)) = 0 ]; then
elif [ $((n % 3)) -eq 0 ]; then
echo Fizz
elif [ $((n % 5)) = 0 ]; then
elif [ $((n % 5)) -eq 0 ]; then
echo Buzz
else
echo $n
fi
n=$((n + 1))
done

View file

@ -7,10 +7,10 @@ Dim i As Integer
Tb(i) = i
If i Mod 15 = 0 Then
Tb(i) = "FizzBuzz"
ElseIf i Mod 3 = 0 Then
Tb(i) = "Fizz"
ElseIf i Mod 5 = 0 Then
Tb(i) = "Buzz"
ElseIf i Mod 3 = 0 Then
Tb(i) = "Fizz"
End If
Next
Debug.Print Join(Tb, vbCrLf)

View file

@ -0,0 +1,10 @@
Sub FizzBuzz()
Dim i As Integer
Dim T(1 To 99) As Variant
For i = 1 To 99 Step 3
T(i + 0) = IIf((i + 0) Mod 5 = 0, "Buzz", i)
T(i + 1) = IIf((i + 1) Mod 5 = 0, "Buzz", i + 1)
T(i + 2) = IIf((i + 2) Mod 5 = 0, "FizzBuzz", "Fizz")
Next i
Debug.Print Join(T, ", ") & ", Buzz"
End Sub

View file

@ -0,0 +1,104 @@
; x86_64 linux nasm
section .bss
number resb 4
section .data
fizz: db "Fizz"
buzz: db "Buzz"
newLine: db 10
section .text
global _start
_start:
mov rax, 1 ; initialize counter
loop:
push rax
call fizzBuzz
pop rax
inc rax
cmp rax, 100
jle loop
mov rax, 60
mov rdi, 0
syscall
fizzBuzz:
mov r10, rax
mov r15, 0 ; boolean fizz or buzz
checkFizz:
xor rdx, rdx ; clear rdx for division
mov rbx, 3
div rbx
cmp rdx, 0 ; modulo result here
jne checkBuzz
mov r15, 1
mov rsi, fizz
mov rdx, 4
mov rax, 1
mov rdi, 1
syscall
checkBuzz:
mov rax, r10
xor rdx, rdx
mov rbx, 5
div rbx
cmp rdx, 0
jne finishLine
mov r15, 1
mov rsi, buzz
mov rdx, 4
mov rax, 1
mov rdi, 1
syscall
finishLine: ; print number if no fizz or buzz
cmp r15, 1
je nextLine
mov rax, r10
call printNum
ret
nextLine:
mov rsi, newLine
mov rdx, 1
mov rax, 1
mov rdi, 1
syscall
ret
printNum: ; write proper digits into number buffer
cmp rax, 100
jl lessThanHundred
mov byte [number], 49
mov byte [number + 1], 48
mov byte [number + 2], 48
mov rdx, 3
jmp print
lessThanHundred: ; get digits to write through division
xor rdx, rdx
mov rbx, 10
div rbx
add rdx, 48
cmp rax, 0
je lessThanTen
add rax, 48
mov byte [number], al
mov byte [number + 1], dl
mov rdx, 2
jmp print
lessThanTen:
mov byte [number], dl
mov rdx, 1
print:
mov byte [number + rdx], 10 ; add newline
inc rdx
mov rax, 1
mov rdi, 1
mov rsi, number
syscall
ret

View file

@ -0,0 +1,11 @@
For i As Integer = 1 To 100
If i Mod 3 = 0 And i Mod 5 = 0 Then
Print("FizzBuzz")
ElseIf i Mod 3 = 0 Then
Print("Fizz")
ElseIf i Mod 5 = 0 Then
Print("Buzz")
Else
Print(Str(i))
End If
Next

View file

@ -0,0 +1,12 @@
For i As Integer = 1 To 100
Select Case True
Case i Mod 3 = 0 And i Mod 5 = 0
Print("FizzBuzz")
Case i Mod 3 = 0
Print("Fizz")
Case i Mod 5 = 0
Print("Buzz")
Else
Print(Str(i))
End Select
Next