June 2018 Update

This commit is contained in:
Ingy döt Net 2018-06-22 20:57:24 +00:00
parent ba8067c3b7
commit 22f33d4004
5278 changed files with 84726 additions and 14379 deletions

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,16 @@
'Free BASIC
DIM AS ULong n
FOR n = 1 TO 100
If n MOD 15 = 0 Then
PRINT "FizzBuzz"
ElseIF n MOD 3 = 0 Then
PRINT "Fizz"
ElseIF n MOD 5 = 0 Then
PRINT "Buzz"
Else
PRINT ; n
End If
NEXT n

View file

@ -1,9 +1 @@
(defn fizzbuzz [start finish]
(map (fn [n]
(cond
(zero? (mod n 15)) "FizzBuzz"
(zero? (mod n 3)) "Fizz"
(zero? (mod n 5)) "Buzz"
:else n))
(range start finish)))
(fizzbuzz 1 100)
(doseq [x (range 1 101)] (println x (str (when (zero? (mod x 3)) "fizz") (when (zero? (mod x 5)) "buzz"))))

View file

@ -1,4 +1,2 @@
(take 100
(map #(if (pos? (compare %1 %2)) %1 %2)
(map str (drop 1 (range)))
(map str (cycle ["" "" "Fizz"]) (cycle ["" "" "" "" "Buzz"]))))
(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

@ -1,19 +1,4 @@
;;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))))
(take 100
(map #(if (pos? (compare %1 %2)) %1 %2)
(map str (drop 1 (range)))
(map str (cycle ["" "" "Fizz"]) (cycle ["" "" "" "" "Buzz"]))))

View file

@ -1,6 +1,19 @@
(take 100
(map #(str %1 %2 (if-not (or %1 %2) %3))
(cycle [nil nil "Fizz"])
(cycle [nil nil nil nil "Buzz"])
(rest (range))
))
;;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))))

View file

@ -1,18 +1,6 @@
(take 100
(
(fn [& fbspec]
(let [
fbseq #(->> (repeat nil) (cons %2) (take %1) reverse cycle)
strfn #(apply str (if (every? nil? (rest %&)) (first %&)) (rest %&))
]
(->>
fbspec
(partition 2)
(map #(apply fbseq %))
(apply map strfn (rest (range)))
) ;;endthread
) ;;endlet
) ;;endfn
3 "Fizz" 5 "Buzz" 7 "Bazz"
) ;;endfn apply
) ;;endtake
(map #(str %1 %2 (if-not (or %1 %2) %3))
(cycle [nil nil "Fizz"])
(cycle [nil nil nil nil "Buzz"])
(rest (range))
))

View file

@ -0,0 +1,18 @@
(take 100
(
(fn [& fbspec]
(let [
fbseq #(->> (repeat nil) (cons %2) (take %1) reverse cycle)
strfn #(apply str (if (every? nil? (rest %&)) (first %&)) (rest %&))
]
(->>
fbspec
(partition 2)
(map #(apply fbseq %))
(apply map strfn (rest (range)))
) ;;endthread
) ;;endlet
) ;;endfn
3 "Fizz" 5 "Buzz" 7 "Bazz"
) ;;endfn apply
) ;;endtake

View file

@ -1,5 +1,9 @@
(map (fn [x] (cond (zero? (mod x 15)) "FizzBuzz"
(zero? (mod x 5)) "Buzz"
(zero? (mod x 3)) "Fizz"
:else x))
(range 1 101))
(defn fizzbuzz [start finish]
(map (fn [n]
(cond
(zero? (mod n 15)) "FizzBuzz"
(zero? (mod n 3)) "Fizz"
(zero? (mod n 5)) "Buzz"
:else n))
(range start finish)))
(fizzbuzz 1 100)

View file

@ -1 +1,5 @@
(map #(let [s (str (if (zero? (mod % 3)) "Fizz") (if (zero? (mod % 5)) "Buzz"))] (if (empty? s) % s)) (range 1 101))
(map (fn [x] (cond (zero? (mod x 15)) "FizzBuzz"
(zero? (mod x 5)) "Buzz"
(zero? (mod x 3)) "Fizz"
:else x))
(range 1 101))

View file

@ -1,6 +1 @@
(def fizzbuzz (map
#(cond (zero? (mod % 15)) "FizzBuzz"
(zero? (mod % 5)) "Buzz"
(zero? (mod % 3)) "Fizz"
:else %)
(iterate inc 1)))
(map #(let [s (str (if (zero? (mod % 3)) "Fizz") (if (zero? (mod % 5)) "Buzz"))] (if (empty? s) % s)) (range 1 101))

View file

@ -1,13 +1,6 @@
(defn fizz-buzz
([] (fizz-buzz (range 1 101)))
([lst]
(letfn [(fizz? [n] (zero? (mod n 3)))
(buzz? [n] (zero? (mod n 5)))]
(let [f "Fizz"
b "Buzz"
items (map (fn [n]
(cond (and (fizz? n) (buzz? n)) (str f b)
(fizz? n) f
(buzz? n) b
:else n))
lst)] items))))
(def fizzbuzz (map
#(cond (zero? (mod % 15)) "FizzBuzz"
(zero? (mod % 5)) "Buzz"
(zero? (mod % 3)) "Fizz"
:else %)
(iterate inc 1)))

View file

@ -1,6 +1,13 @@
(map (fn [n]
(if-let [fb (seq (concat (when (zero? (mod n 3)) "Fizz")
(when (zero? (mod n 5)) "Buzz")))]
(apply str fb)
n))
(range 1 101))
(defn fizz-buzz
([] (fizz-buzz (range 1 101)))
([lst]
(letfn [(fizz? [n] (zero? (mod n 3)))
(buzz? [n] (zero? (mod n 5)))]
(let [f "Fizz"
b "Buzz"
items (map (fn [n]
(cond (and (fizz? n) (buzz? n)) (str f b)
(fizz? n) f
(buzz? n) b
:else n))
lst)] items))))

View file

@ -1,4 +1,6 @@
(take 100 (map #(let [s (str %2 %3) ] (if (seq s) s (inc %)) )
(range)
(cycle [ "" "" "Fizz" ])
(cycle [ "" "" "" "" "Buzz" ])))
(map (fn [n]
(if-let [fb (seq (concat (when (zero? (mod n 3)) "Fizz")
(when (zero? (mod n 5)) "Buzz")))]
(apply str fb)
n))
(range 1 101))

View file

@ -1 +1,4 @@
(map #(nth (conj (cycle [% % "Fizz" % "Buzz" "Fizz" % % "Fizz" "Buzz" % "Fizz" % % "FizzBuzz"]) %) %) (range 1 101))
(take 100 (map #(let [s (str %2 %3) ] (if (seq s) s (inc %)) )
(range)
(cycle [ "" "" "Fizz" ])
(cycle [ "" "" "" "" "Buzz" ])))

View file

@ -1,2 +1 @@
(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)))
(map #(nth (conj (cycle [% % "Fizz" % "Buzz" "Fizz" % % "Fizz" "Buzz" % "Fizz" % % "FizzBuzz"]) %) %) (range 1 101))

View file

@ -0,0 +1,23 @@
;; Project : FizzBuzz
;; Date : 2018/03/07
;; Author : Gal Zsolt [~ CalmoSoft ~]
;; Email : <calmosoft@gmail.com>
(defun fizzbuzz (&optional n)
(let ((n (or n 1)))
(if (> n 100)
nil
(progn
(let ((mult-3 (is-mult-p n 3))
(mult-5 (is-mult-p n 5)))
(if mult-3
(princ "Fizz"))
(if mult-5
(princ "Buzz"))
(if (not (or mult-3 mult-5))
(princ n))
(princ #\linefeed)
(fizzbuzz (+ n 1)))))))
(defun is-mult-p (n multiple)
(= (rem n multiple) 0))
(fizzbuzz 1)

View file

@ -1,4 +1,4 @@
USING: math kernel io math.ranges ;
USING: math kernel io math.functions math.parser math.ranges ;
IN: fizzbuzz
: fizz ( n -- str ) 3 divisor? "Fizz" "" ? ;
: buzz ( n -- str ) 5 divisor? "Buzz" "" ? ;

View file

@ -1 +1 @@
1.upto(100, { i -> println "${i % 3 ? '' : 'Fizz'}${i % 5 ? '' : 'Buzz'}" ?: i })
1.upto(100) { i -> println "${i % 3 ? '' : 'Fizz'}${i % 5 ? '' : 'Buzz'}" ?: i }

View file

@ -1,4 +1,4 @@
for i = 1:100
for i in 1:100
if i % 15 == 0
println("FizzBuzz")
elseif i % 3 == 0

View file

@ -1,4 +1 @@
println( [ i%15 == 0? "FizzBuzz" :
i%5 == 0? "Buzz" :
i%3 == 0? "Fizz" :
i for i = 1:100 ] )
collect(i % 15 == 0 ? "FizzBuzz" : i % 5 == 0 ? "Buzz" : i % 3 == 0 ? "Fizz" : i for i in 1:100) |> println

View file

@ -1,4 +1,2 @@
fb(i::Int) = "Fizz" ^ (i%3==0) *
"Buzz" ^ (i%5==0) *
string(i) ^ (i%3!=0 && i%5!=0)
for i=1:100 println(fb(i)) end
fb(i::Integer) = "Fizz" ^ (i % 3 == 0) * "Buzz" ^ (i % 5 == 0) * dec(i) ^ (i % 3 != 0 && i % 5 != 0)
for i in 1:100 println(fb(i)) end

View file

@ -1 +1 @@
map((x) -> x % 15 == 0 ? "FizzBuzz" : (x % 5 == 0 ? "Buzz" : (x % 3 == 0 ? "Fizz" : x)), 1:100)
println.(map(fb, 1:100))

View file

@ -1,7 +1,4 @@
fib(i) = let result = ""
(i%3 == 0 && (result *="Fizz" ; true)) |
(i%5 == 0 && (result *="Buzz" ; true)) ||
(result = string(i))
result
end
println([fib(i) for i = 1:100])
for i in 1:100
msg = "Fizz" ^ (i % 3 == 0) * "Buzz" ^ (i % 5 == 0)
println(isempty(msg) ? i : msg)
end

View file

@ -0,0 +1,46 @@
MODULE Fizzbuzz;
FROM FormatString IMPORT FormatString;
FROM Terminal IMPORT WriteString,WriteLn,ReadChar;
TYPE CB = PROCEDURE(INTEGER);
PROCEDURE Fizz(n : INTEGER);
BEGIN
IF n MOD 3 = 0 THEN
WriteString("Fizz");
Buzz(n,Newline)
ELSE
Buzz(n,WriteInt)
END
END Fizz;
PROCEDURE Buzz(n : INTEGER; f : CB);
BEGIN
IF n MOD 5 = 0 THEN
WriteString("Buzz");
WriteLn
ELSE
f(n)
END
END Buzz;
PROCEDURE WriteInt(n : INTEGER);
VAR buf : ARRAY[0..9] OF CHAR;
BEGIN
FormatString("%i\n", buf, n);
WriteString(buf)
END WriteInt;
PROCEDURE Newline(n : INTEGER);
BEGIN
WriteLn
END Newline;
VAR i : INTEGER;
BEGIN
FOR i:=1 TO 30 DO
Fizz(i)
END;
ReadChar
END Fizzbuzz.

View file

@ -1,3 +1,6 @@
(for N 100
(prinl
(or (pack (at (0 . 3) "Fizz") (at (0 . 5) "Buzz")) N) ) )
# Above, we simply count till 100 'prin'-ting number 'at' 3rd ('Fizz'), 5th ('Buzz') and 'pack'-ing 15th number ('FizzBuzz').
# Rest of the times 'N' is printed as it loops in 'for'.

View file

@ -1 +1,20 @@
repeat i 100 [case/all [i // 3 = 0 [print"fizz"] i // 5 = 0 [print "buzz"] 1 [print i]]]
REBOL [
Title: "FizzBuzz"
Author: oofoe
Date: 2009-12-10
URL: http://rosettacode.org/wiki/FizzBuzz
]
; Concatenative. Note use of 'case/all' construct to evaluate all
; conditions. I use 'copy' to allocate a new string each time through
; the loop -- otherwise 'x' would get very long...
repeat i 100 [
x: copy ""
case/all [
0 = mod i 3 [append x "Fizz"]
0 = mod i 5 [append x "Buzz"]
"" = x [x: mold i]
]
print x
]

View file

@ -1,20 +1,7 @@
REBOL [
Title: "FizzBuzz"
Author: oofoe
Date: 2009-12-10
URL: http://rosettacode.org/wiki/FizzBuzz
]
; Concatenative. Note use of 'case/all' construct to evaluate all
; conditions. I use 'copy' to allocate a new string each time through
; the loop -- otherwise 'x' would get very long...
repeat i 100 [
x: copy ""
case/all [
0 = mod i 3 [append x "Fizz"]
0 = mod i 5 [append x "Buzz"]
"" = x [x: mold i]
]
print x
print switch/default 0 compose [
(mod i 15) ["fizzbuzz"]
(mod i 3) ["fizz"]
(mod i 5) ["buzz"]
][i]
]

View file

@ -1,11 +1 @@
repeat i 100 [
print switch/default 0 compose [
(mod i 15) ["fizzbuzz"]
(mod i 3) ["fizz"]
(mod i 5) ["buzz"]
][i]
]
; And minimized version:
repeat i 100[j:""if 0 = mod i 3[j:"fizz"]if 0 = mod i 5[j: join j"buzz"]if j =""[j: i]print j]
repeat i 100[j:""if i // 3 = 0[j:"fizz"]if i // 5 = 0[j: join j"buzz"]if""= j[j: i]print j]

View file

@ -1,11 +1,9 @@
use std::borrow::Cow; // Allows us to avoid unnecessary allocations
fn main() {
let result = (1..101).map(|n| match (n % 3, n % 5) {
(0, 0) => "FizzBuzz".to_owned(),
(0, _) => "Fizz".to_owned(),
(_, 0) => "Buzz".to_owned(),
_ => n.to_string()
});
for r in result {
println!("{}", r);
}
(1..101).map(|n| match (n % 3, n % 5) {
(0, 0) => "FizzBuzz".into(),
(0, _) => "Fizz".into(),
(_, 0) => "Buzz".into(),
_ => Cow::from(n.to_string())
}).for_each(|n| println!("{}", n));
}

View file

@ -1,11 +1,11 @@
use std::borrow::Cow;
fn main() {
for i in 1..101 {
let word = match (i % 3, i % 5) {
(0, 0) => "FizzBuzz".to_owned(),
(0, _) => "Fizz".to_owned(),
(_, 0) => "Buzz".to_owned(),
_ => i.to_string().to_owned(),
};
println!("{}", word);
println!("{}", match (i % 3, i % 5) {
(0, 0) => "FizzBuzz".into(),
(0, _) => "Fizz".into(),
(_, 0) => "Buzz".into(),
_ => Cow::from(i.to_string()),
});
}
}

View file

@ -2,14 +2,14 @@ begin
integer i;
for i := 1 step 1 until 100 do
begin
if mod( i, 15 ) = 0 then
outtext( "FizzBuzz" )
else if mod( i, 3 ) = 0 then
outtext( "Fizz" )
else if mod( i, 5 ) = 0 then
outtext( "Buzz" )
else
outint( i, 3 );
boolean fizzed;
fizzed := 0 = mod(i, 3);
if fizzed then
outtext("Fizz");
if mod(i, 5) = 0 then
outtext("Buzz")
else if not fizzed then
outint(i, 3);
outimage
end;
end

View file

@ -0,0 +1,17 @@
program define fizzbuzz
args n
forvalues i = 1/`n' {
if mod(`i',15) == 0 {
display "FizzBuzz"
}
else if mod(`i',5) == 0 {
display "Buzz"
}
else if mod(`i',3) == 0 {
display "Fizz"
}
else {
display `i'
}
}
end

View file

@ -0,0 +1,6 @@
for i in 1...100{
var s:String?
if i%3==0{s="Fizz"}
if i%5==0{s=(s ?? "")+"Buzz"}
print(s ?? i)
}

View file

@ -0,0 +1,17 @@
Option Explicit
Sub FizzBuzz()
Dim Tb(1 To 100) As Variant
Dim i As Integer
For i = 1 To 100
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"
End If
Next
Debug.Print Join(Tb, vbCrLf)
End Sub