Time for an 2014 update…

This commit is contained in:
Ingy döt Net 2014-01-17 05:32:22 +00:00
parent 372c577f83
commit 09687c4926
2520 changed files with 34227 additions and 7318 deletions

View file

@ -11,58 +11,58 @@
;------------------------------------------------------
; Constant Section
;
FizzCt = 3 Fizz Counter (must be < 255)
BuzzCt = 5 Buzz Counter (must be < 255)
Lower = 1 Loop start value (must be 1)
Upper = 100 Loop end value (must be < 255)
CharOut = $fded Specific to the Apple II
IntOut = $ed24 Specific to ROM Applesoft
FizzCt = 3 ;Fizz Counter (must be < 255)
BuzzCt = 5 ;Buzz Counter (must be < 255)
Lower = 1 ;Loop start value (must be 1)
Upper = 100 ;Loop end value (must be < 255)
CharOut = $fded ;Specific to the Apple II
IntOut = $ed24 ;Specific to ROM Applesoft
;======================================================
.or $0f00
;------------------------------------------------------
; The main program
;
main ldx #Lower init LoopCt
main ldx #Lower ;init LoopCt
lda #FizzCt
sta Fizz init FizzCt
sta Fizz ;init FizzCt
lda #BuzzCt
sta Buzz init BuzzCt
next ldy #0 reset string pointer (y)
dec Fizz LoopCt mod FizzCt == 0?
bne noFizz yes:
sta Buzz ;init BuzzCt
next ldy #0 ;reset string pointer (y)
dec Fizz ;LoopCt mod FizzCt == 0?
bne noFizz ; yes:
lda #FizzCt
sta Fizz restore FizzCt
ldy #sFizz-str point y to "Fizz"
jsr puts output "Fizz"
noFizz dec Buzz LoopCt mod BuzzCt == 0?
bne noBuzz yes:
sta Fizz ; restore FizzCt
ldy #sFizz-str ; point y to "Fizz"
jsr puts ; output "Fizz"
noFizz dec Buzz ;LoopCt mod BuzzCt == 0?
bne noBuzz ; yes:
lda #BuzzCt
sta Buzz restore BuzzCt
ldy #sBuzz-str point y to "Buzz"
jsr puts output "Buzz"
noBuzz dey any output yet this cycle?
bpl noInt no:
txa save LoopCt
sta Buzz ; restore BuzzCt
ldy #sBuzz-str ; point y to "Buzz"
jsr puts ; output "Buzz"
noBuzz dey ;any output yet this cycle?
bpl noInt ; no:
txa ; save LoopCt
pha
lda #0 set up regs for IntOut
jsr IntOut output itoa(LoopCt)
lda #0 ; set up regs for IntOut
jsr IntOut ; output itoa(LoopCt)
pla
tax restore LoopCt
tax ; restore LoopCt
noInt ldy #sNL-str
jsr puts output "\n"
inx increment LoopCt
cpx #Upper+1 LoopCt >= Upper+1?
bcc next no: loop back
rts yes: end main
jsr puts ;output "\n"
inx ;increment LoopCt
cpx #Upper+1 ;LoopCt >= Upper+1?
bcc next ; no: loop back
rts ; yes: end main
;------------------------------------------------------
; Output zero-terminated string @ (str+y)
; (Entry point is puts, not outch)
;
outch jsr CharOut output string char
iny advance string ptr
puts lda str,y get a string char
bne outch output and loop if non-zero
rts return
outch jsr CharOut ;output string char
iny ;advance string ptr
puts lda str,y ;get a string char
bne outch ;output and loop if non-zero
rts ;return
;------------------------------------------------------
; String literals (in '+128' ascii, Apple II style)
;

View file

@ -0,0 +1,10 @@
for i range 1 100:
if = 0 % i 15:
"FizzBuzz"
elseif = 0 % i 3:
"Fizz"
elseif = 0 % i 5:
"Buzz"
else:
i
!print

View file

@ -1,5 +1,5 @@
# idiomatic buffer builder, 1st alternative
procedure main()
    every i := 1 to 100 do
        write("" ~== (if i % 3 = 0 then "Fizz" else "") || (if i % 5 == 0 then "Buzz" else "") | i)
every i := 1 to 100 do
write("" ~== (if i % 3 = 0 then "Fizz" else "") || (if i % 5 == 0 then "Buzz" else "") | i)
end

View file

@ -1,8 +1,8 @@
# idiomatic buffer builder, 2nd alternative
procedure main()
   every i := 1 to 100 do {
       s   := if i%3 = 0 then "Fizz" else ""
       s ||:= if i%5 = 0 then "Buzz"
       write(("" ~= s) | i)
   }
every i := 1 to 100 do {
s := if i%3 = 0 then "Fizz" else ""
s ||:= if i%5 = 0 then "Buzz"
write(("" ~= s) | i)
}
end

View file

@ -1,8 +1 @@
(function() {
var i;
for (i = 1; i <= 100; i++) {
console.log([i % 3 === 0 ? 'Fizz' : void 0] + [i % 5 === 0 ? 'Buzz' : void 0] || i);
}
}).call(this);
for(i=0;i<100;console.log(++i%15?i%5?i%3?i:f='Fizz':b='Buzz':f+b));

View file

@ -1,25 +1,8 @@
var divs = [15, 3, 5];
var says = ['FizzBuzz', 'Fizz', 'Buzz'];
(function() {
var i;
function fizzBuzz(first, last) {
for (var n = first; n <= last; n++) {
print(getFizzBuzz(n));
}
}
for (i = 1; i <= 100; i++) {
console.log([i % 3 === 0 ? 'Fizz' : void 0] + [i % 5 === 0 ? 'Buzz' : void 0] || i);
}
function getFizzBuzz(n) {
var sayWhat = n;
for (var d = 0; d < divs.length; d++) {
if (isMultOf(n, divs[d])) {
sayWhat = says[d];
break;
}
}
return sayWhat;
}
function isMultOf(n, d) {
return n % d == 0;
}
fizzBuzz(1, 100);
}).call(this);

View file

@ -0,0 +1,25 @@
var divs = [15, 3, 5];
var says = ['FizzBuzz', 'Fizz', 'Buzz'];
function fizzBuzz(first, last) {
for (var n = first; n <= last; n++) {
print(getFizzBuzz(n));
}
}
function getFizzBuzz(n) {
var sayWhat = n;
for (var d = 0; d < divs.length; d++) {
if (isMultOf(n, divs[d])) {
sayWhat = says[d];
break;
}
}
return sayWhat;
}
function isMultOf(n, d) {
return n % d == 0;
}
fizzBuzz(1, 100);

View file

@ -0,0 +1,19 @@
for (int i = 0; i < width; i++) {
if (i % 3 == 0 && i % 5 == 0) {
stroke(255, 255, 0);
println("FizzBuzz!");
}
else if (i % 5 == 0) {
stroke(0, 255, 0);
println("Buzz");
}
else if (i % 3 == 0) {
stroke(255, 0, 0);
println("Fizz");
}
else {
stroke(0, 0, 255);
println(i);
}
line(i, 0, i, height);
}

View file

@ -0,0 +1,5 @@
for (int i = 0; i < width; i++) {
stroke((i % 5 == 0 && i % 3 == 0) ? #FFFF00 : (i % 5 == 0) ? #00FF00 : (i % 3 == 0) ? #FF0000 : #0000FF);
line(i, 0, i, height);
println((i % 5 == 0 && i % 3 == 0) ? "FizzBuzz!" : (i % 5 == 0) ? "Buzz" : (i % 3 == 0) ? "Fizz" : i);
}

View file

@ -0,0 +1,20 @@
% N /3? /5? V
fizzbuzz(_, yes, yes, 'FizzBuzz').
fizzbuzz(_, yes, no, 'Fizz').
fizzbuzz(_, no, yes, 'Buzz').
fizzbuzz(N, no, no, N).
% Unifies V with 'yes' if D divides evenly into N, 'no' otherwise.
divisible_by(N, D, V) :-
( 0 is N mod D -> V = yes
; V = no).
% Print 'Fizz', 'Buzz', 'FizzBuzz' or N as appropriate.
fizz_buzz_or_n(N) :-
divisible_by(N, 3, Fizz),
divisible_by(N, 5, Buzz),
fizzbuzz(N, Fizz, Buzz, FB),
format("~p -> ~p~n", [N, FB]).
main :-
foreach(between(1,100, N), fizz_buzz_or_n(N)).

View file

@ -1,11 +1,2 @@
SELECT i, fizzbuzz
FROM
(SELECT i,
CASE
WHEN i % 15 = 0 THEN 'FizzBuzz'
WHEN i % 5 = 0 THEN 'Buzz'
WHEN i % 3 = 0 THEN 'Fizz'
ELSE NULL
END AS fizzbuzz
FROM generate_series(1,100) AS i) AS fb
WHERE fizzbuzz IS NOT NULL;
select nvl(decode(mod(n,3),0,'Fizz')||decode(mod(n,5),0,'Buzz'),n)
from (select level n from dual connect by level<=100)

View file

@ -1,15 +1,11 @@
WITH nums (n, fizzbuzz ) AS (
SELECT 1, CONVERT(nvarchar, 1) UNION ALL
SELECT
(n + 1) as n1,
CASE
WHEN (n + 1) % 15 = 0 THEN 'FizzBuzz'
WHEN (n + 1) % 3 = 0 THEN 'Fizz'
WHEN (n + 1) % 5 = 0 THEN 'Buzz'
ELSE CONVERT(nvarchar, (n + 1))
END
FROM nums WHERE n < 100
)
SELECT n, fizzbuzz FROM nums
ORDER BY n ASC
OPTION ( MAXRECURSION 100 )
SELECT i, fizzbuzz
FROM
(SELECT i,
CASE
WHEN i % 15 = 0 THEN 'FizzBuzz'
WHEN i % 5 = 0 THEN 'Buzz'
WHEN i % 3 = 0 THEN 'Fizz'
ELSE NULL
END AS fizzbuzz
FROM generate_series(1,100) AS i) AS fb
WHERE fizzbuzz IS NOT NULL;

View file

@ -1,24 +1,7 @@
-- Load some numbers
CREATE TABLE numbers(i INTEGER);
INSERT INTO numbers VALUES(1);
INSERT INTO numbers SELECT i + (SELECT MAX(i) FROM numbers) FROM numbers;
INSERT INTO numbers SELECT i + (SELECT MAX(i) FROM numbers) FROM numbers;
INSERT INTO numbers SELECT i + (SELECT MAX(i) FROM numbers) FROM numbers;
INSERT INTO numbers SELECT i + (SELECT MAX(i) FROM numbers) FROM numbers;
INSERT INTO numbers SELECT i + (SELECT MAX(i) FROM numbers) FROM numbers;
INSERT INTO numbers SELECT i + (SELECT MAX(i) FROM numbers) FROM numbers;
INSERT INTO numbers SELECT i + (SELECT MAX(i) FROM numbers) FROM numbers;
-- Define the fizzes and buzzes
CREATE TABLE fizzbuzz (message VARCHAR(8), divisor INTEGER);
INSERT INTO fizzbuzz VALUES('fizz', 3);
INSERT INTO fizzbuzz VALUES('buzz', 5);
INSERT INTO fizzbuzz VALUES('fizzbuzz', 15);
-- Play fizzbuzz
SELECT COALESCE(max(message),CAST(i AS VARCHAR(99))) as result
FROM numbers LEFT OUTER JOIN fizzbuzz ON MOD(i,divisor) = 0
GROUP BY i
HAVING i <= 100
ORDER BY i;
-- Tidy up
DROP TABLE fizzbuzz;
DROP TABLE numbers;
SELECT COALESCE(FIZZ || BUZZ, FIZZ, BUZZ, OUTPUT) AS FIZZBUZZ FROM
(SELECT GENERATE_SERIES AS FULL_SERIES, TO_CHAR(GENERATE_SERIES,'99') AS OUTPUT
FROM GENERATE_SERIES(1,100)) F LEFT JOIN
(SELECT TEXT 'Fizz' AS FIZZ, GENERATE_SERIES AS FIZZ_SERIES FROM GENERATE_SERIES(0,100,3)) FIZZ ON
FIZZ.FIZZ_SERIES = F.FULL_SERIES LEFT JOIN
(SELECT TEXT 'Buzz' AS BUZZ, GENERATE_SERIES AS BUZZ_SERIES FROM GENERATE_SERIES(0,100,5)) BUZZ ON
BUZZ.BUZZ_SERIES = F.FULL_SERIES;

View file

@ -1,16 +1,15 @@
declare
v_count integer;
begin
for v_count in 1..100 loop
if(mod(v_count, 15) = 0) then
dbms_output.put_line('Fizz Buzz');
elsif(mod(v_count, 3) = 0) then
dbms_output.put_line('Fizz');
elsif(mod(v_count, 5) = 0) then
dbms_output.put_line('Buzz');
else
dbms_output.put_line(v_count);
end if;
end loop;
end;
WITH nums (n, fizzbuzz ) AS (
SELECT 1, CONVERT(nvarchar, 1) UNION ALL
SELECT
(n + 1) as n1,
CASE
WHEN (n + 1) % 15 = 0 THEN 'FizzBuzz'
WHEN (n + 1) % 3 = 0 THEN 'Fizz'
WHEN (n + 1) % 5 = 0 THEN 'Buzz'
ELSE CONVERT(nvarchar, (n + 1))
END
FROM nums WHERE n < 100
)
SELECT n, fizzbuzz FROM nums
ORDER BY n ASC
OPTION ( MAXRECURSION 100 )

View file

@ -0,0 +1,24 @@
-- Load some numbers
CREATE TABLE numbers(i INTEGER);
INSERT INTO numbers VALUES(1);
INSERT INTO numbers SELECT i + (SELECT MAX(i) FROM numbers) FROM numbers;
INSERT INTO numbers SELECT i + (SELECT MAX(i) FROM numbers) FROM numbers;
INSERT INTO numbers SELECT i + (SELECT MAX(i) FROM numbers) FROM numbers;
INSERT INTO numbers SELECT i + (SELECT MAX(i) FROM numbers) FROM numbers;
INSERT INTO numbers SELECT i + (SELECT MAX(i) FROM numbers) FROM numbers;
INSERT INTO numbers SELECT i + (SELECT MAX(i) FROM numbers) FROM numbers;
INSERT INTO numbers SELECT i + (SELECT MAX(i) FROM numbers) FROM numbers;
-- Define the fizzes and buzzes
CREATE TABLE fizzbuzz (message VARCHAR(8), divisor INTEGER);
INSERT INTO fizzbuzz VALUES('fizz', 3);
INSERT INTO fizzbuzz VALUES('buzz', 5);
INSERT INTO fizzbuzz VALUES('fizzbuzz', 15);
-- Play fizzbuzz
SELECT COALESCE(max(message),CAST(i AS VARCHAR(99))) as result
FROM numbers LEFT OUTER JOIN fizzbuzz ON MOD(i,divisor) = 0
GROUP BY i
HAVING i <= 100
ORDER BY i;
-- Tidy up
DROP TABLE fizzbuzz;
DROP TABLE numbers;

View file

@ -0,0 +1,14 @@
local
fun fbstr i =
case (i mod 3 = 0, i mod 5 = 0) of
(true , true ) => "FizzBuzz"
| (true , false) => "Fizz"
| (false, true ) => "Buzz"
| (false, false) => Int.toString i
fun fizzbuzz' (n, j) =
if n = j then () else (print (fbstr j ^ "\n"); fizzbuzz' (n, j+1))
in
fun fizzbuzz n = fizzbuzz' (n, 1)
val _ = fizzbuzz 100
end

View file

@ -0,0 +1,8 @@
local
fun fb i = let val fizz = i mod 3 = 0 andalso (print "Fizz"; true)
val buzz = i mod 5 = 0 andalso (print "Buzz"; true)
in fizz orelse buzz orelse (print (Int.toString i); true) end
in
fun fizzbuzz n = (List.tabulate (n, fn i => (fb (i+1); print "\n")); ())
val _ = fizzbuzz 100
end

View file

@ -1,14 +0,0 @@
fun output x =
case (x mod 3 = 0, x mod 5 = 0) of
(true , true ) => "FizzBuzz"
| (true , false) => "Fizz"
| (false, true ) => "Buzz"
| (false, false) => Int.toString x
val () = let
fun aux i = if i <= 100 then (print (output i ^ "\n");
aux (i+1))
else ()
in
aux 1
end

View file

@ -1,26 +1,11 @@
'using the IF/ELSEIF ladder
function fb( n )
if n mod 15 = 0 then
fb = "FizzBuzz"
elseif n mod 5 = 0 then
fb = "Fizz"
elseif n mod 3 = 0 then
fb = "Buzz"
else
fb = n
end if
end function
'the Mexican IF
function eef( b, p1, p2 )
if b then
eef = p1
else
eef = p2
end if
end function
'using the Mexican IF
function fb2( n )
fb2 = eef( n mod 15 = 0, "FizzBuzz", eef( n mod 5 = 0, "Fizz", eef( n mod 3 = 0, "Buzz", n ) ) )
end function
For i = 1 To 100
If i Mod 15 = 0 Then
WScript.Echo "FizzBuzz"
ElseIf i Mod 5 = 0 Then
WScript.Echo "Buzz"
ElseIf i Mod 3 = 0 Then
WScript.Echo "Fizz"
Else
WScript.Echo i
End If
Next

View file

@ -1,9 +1,7 @@
for i = 1 to 16
wscript.stdout.write fb(i) & " "
next
wscript.echo
for i = 1 to 16
wscript.stdout.write fb2(i) & " "
next
wscript.echo
With WScript.StdOut
For i = 1 To 100
If i Mod 3 = 0 Then .Write "Fizz"
If i Mod 5 = 0 Then .Write "Buzz"
If .Column = 1 Then .WriteLine i Else .WriteLine ""
Next
End With