2016 Update
This commit is contained in:
parent
948b86eafa
commit
dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions
|
|
@ -1,8 +1,17 @@
|
|||
Write a program that prints the integers from 1 to 100.
|
||||
;Task:
|
||||
Write a program that prints the integers from '''1''' to '''100''' (inclusive).
|
||||
|
||||
But for multiples of three print "Fizz" instead of the number,
|
||||
and for the multiples of five print "Buzz". <br>
|
||||
For numbers which are multiples of both three and five print "FizzBuzz". [http://weblog.raganwald.com/2007/01/dont-overthink-fizzbuzz.html]
|
||||
|
||||
FizzBuzz was presented as the lowest level of comprehension
|
||||
required to illustrate adequacy. [http://blog.codinghorror.com/fizzbuzz-the-programmers-stairway-to-heaven/]
|
||||
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>
|
||||
|
|
|
|||
88
Task/FizzBuzz/AppleScript/fizzbuzz-2.applescript
Normal file
88
Task/FizzBuzz/AppleScript/fizzbuzz-2.applescript
Normal file
|
|
@ -0,0 +1,88 @@
|
|||
on run
|
||||
|
||||
intercalate(linefeed, ¬
|
||||
map(fizzBuzz, range(1, 100)))
|
||||
|
||||
end run
|
||||
|
||||
|
||||
-- fizzBuzz :: Int -> String
|
||||
on fizzBuzz(x)
|
||||
caseOf(x, [[my fizzAndBuzz, "FizzBuzz"], ¬
|
||||
[my fizz, "Fizz"], ¬
|
||||
[my buzz, "Buzz"]], ¬
|
||||
x as string)
|
||||
end fizzBuzz
|
||||
|
||||
-- fizzAndBuzz :: Int -> Bool
|
||||
on fizzAndBuzz(n)
|
||||
n mod 15 = 0
|
||||
end fizzAndBuzz
|
||||
|
||||
-- fizz :: Int -> Bool
|
||||
on fizz(n)
|
||||
n mod 3 = 0
|
||||
end fizz
|
||||
|
||||
-- buzz :: Int -> Bool
|
||||
on buzz(n)
|
||||
n mod 5 = 0
|
||||
end buzz
|
||||
|
||||
|
||||
-- GENERIC LIBRARY 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 lambda(e) then return v
|
||||
end repeat
|
||||
return default
|
||||
end caseOf
|
||||
|
||||
-- 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 lambda(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 lambda : f
|
||||
end script
|
||||
end if
|
||||
end mReturn
|
||||
|
||||
-- range :: Int -> Int -> [Int]
|
||||
on range(m, n)
|
||||
if n < m 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 range
|
||||
25
Task/FizzBuzz/AutoIt/fizzbuzz-2.autoit
Normal file
25
Task/FizzBuzz/AutoIt/fizzbuzz-2.autoit
Normal 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.")
|
||||
29
Task/FizzBuzz/COBOL/fizzbuzz-4.cobol
Normal file
29
Task/FizzBuzz/COBOL/fizzbuzz-4.cobol
Normal 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.
|
||||
19
Task/FizzBuzz/Clojure/fizzbuzz-11.clj
Normal file
19
Task/FizzBuzz/Clojure/fizzbuzz-11.clj
Normal 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))))
|
||||
6
Task/FizzBuzz/Clojure/fizzbuzz-12.clj
Normal file
6
Task/FizzBuzz/Clojure/fizzbuzz-12.clj
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
(take 100
|
||||
(map #(str %1 %2 (if-not (or %1 %2) %3))
|
||||
(cycle [nil nil "Fizz"])
|
||||
(cycle [nil nil nil nil "Buzz"])
|
||||
(rest (range))
|
||||
))
|
||||
18
Task/FizzBuzz/Clojure/fizzbuzz-13.clj
Normal file
18
Task/FizzBuzz/Clojure/fizzbuzz-13.clj
Normal 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
|
||||
|
|
@ -1 +1 @@
|
|||
(map #(nth (conj (cycle [% % "Fizz" % "Buzz" "Fizz" % % % "Buzz" % "Fizz" % % "FizzBuzz"]) %) %) (range 1 101))
|
||||
(map #(nth (conj (cycle [% % "Fizz" % "Buzz" "Fizz" % % "Fizz" "Buzz" % "Fizz" % % "FizzBuzz"]) %) %) (range 1 101))
|
||||
|
|
|
|||
|
|
@ -2,6 +2,6 @@
|
|||
<Cfif i mod 15 eq 0>FizzBuzz
|
||||
<Cfelseif i mod 5 eq 0>Fizz
|
||||
<Cfelseif i mod 3 eq 0>Buzz
|
||||
<Cfelse><Cfoutput>#i#</Cfoutput>
|
||||
<Cfelse><Cfoutput>#i# </Cfoutput>
|
||||
</Cfif>
|
||||
</Cfloop>
|
||||
7
Task/FizzBuzz/ColdFusion/fizzbuzz-2.cfm
Normal file
7
Task/FizzBuzz/ColdFusion/fizzbuzz-2.cfm
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
<cfscript>
|
||||
result = "";
|
||||
for(i=1;i<=100;i++){
|
||||
result=ListAppend(result, (i%15==0) ? "FizzBuzz": (i%5==0) ? "Buzz" : (i%3 eq 0)? "Fizz" : i );
|
||||
}
|
||||
WriteOutput(result);
|
||||
</cfscript>
|
||||
|
|
@ -1,9 +1,9 @@
|
|||
#!/usr/bin/env elixir
|
||||
1..100 |> Enum.map(fn i ->
|
||||
cond do
|
||||
rem(i,3*5) == 0 -> "fizzbuzz"
|
||||
rem(i,3) == 0 -> "fizz"
|
||||
rem(i,5) == 0 -> "buzz"
|
||||
rem(i,3*5) == 0 -> "FizzBuzz"
|
||||
rem(i,3) == 0 -> "Fizz"
|
||||
rem(i,5) == 0 -> "Buzz"
|
||||
true -> i
|
||||
end
|
||||
end) |> Enum.each(fn i -> IO.puts i end)
|
||||
|
|
|
|||
|
|
@ -3,8 +3,8 @@ defmodule RC do
|
|||
fizz = Stream.cycle(["", "", "Fizz"])
|
||||
buzz = Stream.cycle(["", "", "", "", "Buzz"])
|
||||
Stream.zip(fizz, buzz)
|
||||
|> Stream.with_index
|
||||
|> Enum.take(limit)
|
||||
|> Enum.with_index
|
||||
|> Enum.each(fn {{f,b},i} ->
|
||||
IO.puts if f<>b=="", do: i+1, else: f<>b
|
||||
end)
|
||||
|
|
|
|||
|
|
@ -5,4 +5,4 @@ defmodule FizzBuzz do
|
|||
def fizzbuzz(n), do: n
|
||||
end
|
||||
|
||||
Enum.map(1..100, &FizzBuzz.fizzbuzz/1)
|
||||
Enum.each(1..100, &IO.puts FizzBuzz.fizzbuzz &1)
|
||||
|
|
|
|||
|
|
@ -1,91 +1,7 @@
|
|||
defmodule BadFizz do
|
||||
# Hand-rolls a bunch of AST before injecting the resulting FizzBuzz code.
|
||||
defmacrop automate_fizz(fizzers, n) do
|
||||
# To begin, we need to process fizzers to produce the various components
|
||||
# we're using in the final assembly. As told by Mickens telling as Antonio
|
||||
# Banderas, first you must specify a mapping function:
|
||||
build_parts = (fn {fz, n} ->
|
||||
ast_ref = {fz |> String.downcase |> String.to_atom, [], __MODULE__}
|
||||
clist = List.duplicate("", n - 1) ++ [fz]
|
||||
cycle = quote do: unquote(ast_ref) = unquote(clist) |> Stream.cycle
|
||||
|
||||
{ast_ref, cycle}
|
||||
end)
|
||||
|
||||
# ...and then a reducing function:
|
||||
collate = (fn
|
||||
({ast_ref, cycle}, {ast_refs, cycles}) ->
|
||||
{[ast_ref | ast_refs], [cycle | cycles]}
|
||||
end)
|
||||
|
||||
# ...and then, my love, when you are done your computation is ready to run
|
||||
# across thousands of fizzbuzz:
|
||||
{ast_refs, cycles} = fizzers
|
||||
|> Code.eval_quoted([], __ENV__) |> elem(0) # Gotta unwrap this mystery code~
|
||||
|> Enum.sort(fn ({_, ap}, {_, bp}) -> ap < bp end) # Sort so that Fizz, 3 < Buzz, 5
|
||||
|> Enum.map(build_parts)
|
||||
|> Enum.reduce({[], []}, collate)
|
||||
|
||||
# Setup the anonymous functions used by Enum.reduce to build our AST components.
|
||||
# This was previously handled by List.foldl, but ejected because reduce/2's
|
||||
# default behavior reduces repetition.
|
||||
#
|
||||
# ...I was tempted to move these into a macro themselves, and thought better of it.
|
||||
build_zip = fn (varname, ast) ->
|
||||
quote do: Stream.zip(unquote(varname), unquote(ast))
|
||||
end
|
||||
build_tuple = fn (varname, ast) ->
|
||||
{:{}, [], [varname, ast]}
|
||||
end
|
||||
build_concat = fn (varname, ast) ->
|
||||
{:<>,
|
||||
[context: __MODULE__, import: Kernel], # Hygiene values may change; accurate to Elixir 1.1.1
|
||||
[varname, ast]}
|
||||
end
|
||||
|
||||
# Toss cycles into a block by hand, then smash ast_refs into
|
||||
# a few different computations on the cycle block results.
|
||||
cycles = {:__block__, [], cycles}
|
||||
tuple = ast_refs |> Enum.reduce(build_tuple)
|
||||
zip = ast_refs |> Enum.reduce(build_zip)
|
||||
concat = ast_refs |> Enum.reduce(build_concat)
|
||||
|
||||
# Finally-- Now that all our components are assembled, we can put
|
||||
# together the fizzbuzz stream pipeline. After quote ends, this
|
||||
# block is injected into the caller's context.
|
||||
quote do
|
||||
unquote(cycles)
|
||||
|
||||
unquote(zip)
|
||||
|> Stream.with_index
|
||||
|> Enum.take(unquote(n))
|
||||
|> Enum.each(fn
|
||||
{unquote(tuple), i} ->
|
||||
ccats = unquote(concat)
|
||||
IO.puts if ccats == "", do: i + 1, else: ccats
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
||||
@doc ~S"""
|
||||
A fizzing, and possibly buzzing function. Somehow, you feel like you've
|
||||
seen this before. An old friend, suddenly appearing in Kafkaesque nightmare...
|
||||
|
||||
...or worse, during a whiteboard interview.
|
||||
"""
|
||||
def fizz(n \\ 100) when is_number(n) do
|
||||
# In reward for all that effort above, we now have the latest in
|
||||
# programmer productivity:
|
||||
#
|
||||
# A DSL for building arbitrary fizzing, buzzing, bazzing, and more!
|
||||
[{"Fizz", 3},
|
||||
{"Buzz", 5}#,
|
||||
#{"Bar", 7},
|
||||
#{"Foo", 243}, # -> Always printed last (largest number)
|
||||
#{"Qux", 34}
|
||||
]
|
||||
|> automate_fizz(n)
|
||||
end
|
||||
f = fn(n) when rem(n,15)==0 -> "FizzBuzz"
|
||||
(n) when rem(n,5)==0 -> "Fizz"
|
||||
(n) when rem(n,3)==0 -> "Buzz"
|
||||
(n) -> n
|
||||
end
|
||||
|
||||
BadFizz.fizz(100) # => Prints to stdout
|
||||
for n <- 1..100, do: IO.puts f.(n)
|
||||
|
|
|
|||
4
Task/FizzBuzz/Elixir/fizzbuzz-6.elixir
Normal file
4
Task/FizzBuzz/Elixir/fizzbuzz-6.elixir
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
Enum.each(1..100, fn i ->
|
||||
str = "#{Enum.at([:Fizz], rem(i,3))}#{Enum.at([:Buzz], rem(i,5))}"
|
||||
IO.puts if str=="", do: i, else: str
|
||||
end)
|
||||
91
Task/FizzBuzz/Elixir/fizzbuzz-7.elixir
Normal file
91
Task/FizzBuzz/Elixir/fizzbuzz-7.elixir
Normal file
|
|
@ -0,0 +1,91 @@
|
|||
defmodule BadFizz do
|
||||
# Hand-rolls a bunch of AST before injecting the resulting FizzBuzz code.
|
||||
defmacrop automate_fizz(fizzers, n) do
|
||||
# To begin, we need to process fizzers to produce the various components
|
||||
# we're using in the final assembly. As told by Mickens telling as Antonio
|
||||
# Banderas, first you must specify a mapping function:
|
||||
build_parts = (fn {fz, n} ->
|
||||
ast_ref = {fz |> String.downcase |> String.to_atom, [], __MODULE__}
|
||||
clist = List.duplicate("", n - 1) ++ [fz]
|
||||
cycle = quote do: unquote(ast_ref) = unquote(clist) |> Stream.cycle
|
||||
|
||||
{ast_ref, cycle}
|
||||
end)
|
||||
|
||||
# ...and then a reducing function:
|
||||
collate = (fn
|
||||
({ast_ref, cycle}, {ast_refs, cycles}) ->
|
||||
{[ast_ref | ast_refs], [cycle | cycles]}
|
||||
end)
|
||||
|
||||
# ...and then, my love, when you are done your computation is ready to run
|
||||
# across thousands of fizzbuzz:
|
||||
{ast_refs, cycles} = fizzers
|
||||
|> Code.eval_quoted([], __ENV__) |> elem(0) # Gotta unwrap this mystery code~
|
||||
|> Enum.sort(fn ({_, ap}, {_, bp}) -> ap < bp end) # Sort so that Fizz, 3 < Buzz, 5
|
||||
|> Enum.map(build_parts)
|
||||
|> Enum.reduce({[], []}, collate)
|
||||
|
||||
# Setup the anonymous functions used by Enum.reduce to build our AST components.
|
||||
# This was previously handled by List.foldl, but ejected because reduce/2's
|
||||
# default behavior reduces repetition.
|
||||
#
|
||||
# ...I was tempted to move these into a macro themselves, and thought better of it.
|
||||
build_zip = fn (varname, ast) ->
|
||||
quote do: Stream.zip(unquote(varname), unquote(ast))
|
||||
end
|
||||
build_tuple = fn (varname, ast) ->
|
||||
{:{}, [], [varname, ast]}
|
||||
end
|
||||
build_concat = fn (varname, ast) ->
|
||||
{:<>,
|
||||
[context: __MODULE__, import: Kernel], # Hygiene values may change; accurate to Elixir 1.1.1
|
||||
[varname, ast]}
|
||||
end
|
||||
|
||||
# Toss cycles into a block by hand, then smash ast_refs into
|
||||
# a few different computations on the cycle block results.
|
||||
cycles = {:__block__, [], cycles}
|
||||
tuple = ast_refs |> Enum.reduce(build_tuple)
|
||||
zip = ast_refs |> Enum.reduce(build_zip)
|
||||
concat = ast_refs |> Enum.reduce(build_concat)
|
||||
|
||||
# Finally-- Now that all our components are assembled, we can put
|
||||
# together the fizzbuzz stream pipeline. After quote ends, this
|
||||
# block is injected into the caller's context.
|
||||
quote do
|
||||
unquote(cycles)
|
||||
|
||||
unquote(zip)
|
||||
|> Stream.with_index
|
||||
|> Enum.take(unquote(n))
|
||||
|> Enum.each(fn
|
||||
{unquote(tuple), i} ->
|
||||
ccats = unquote(concat)
|
||||
IO.puts if ccats == "", do: i + 1, else: ccats
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
||||
@doc ~S"""
|
||||
A fizzing, and possibly buzzing function. Somehow, you feel like you've
|
||||
seen this before. An old friend, suddenly appearing in Kafkaesque nightmare...
|
||||
|
||||
...or worse, during a whiteboard interview.
|
||||
"""
|
||||
def fizz(n \\ 100) when is_number(n) do
|
||||
# In reward for all that effort above, we now have the latest in
|
||||
# programmer productivity:
|
||||
#
|
||||
# A DSL for building arbitrary fizzing, buzzing, bazzing, and more!
|
||||
[{"Fizz", 3},
|
||||
{"Buzz", 5}#,
|
||||
#{"Bar", 7},
|
||||
#{"Foo", 243}, # -> Always printed last (largest number)
|
||||
#{"Qux", 34}
|
||||
]
|
||||
|> automate_fizz(n)
|
||||
end
|
||||
end
|
||||
|
||||
BadFizz.fizz(100) # => Prints to stdout
|
||||
8
Task/FizzBuzz/Forth/fizzbuzz-4.fth
Normal file
8
Task/FizzBuzz/Forth/fizzbuzz-4.fth
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
: n ( n -- n+1 ) dup . 1+ ;
|
||||
: f ( n -- n+1 ) ." Fizz " 1+ ;
|
||||
: b ( n -- n+1 ) ." Buzz " 1+ ;
|
||||
: fb ( n -- n+1 ) ." FizzBuzz " 1+ ;
|
||||
: fb10 ( n -- n+10 ) n n f n b f n n f b ;
|
||||
: fb15 ( n -- n+15 ) fb10 n f n n fb ;
|
||||
: fb100 ( n -- n+100 ) fb15 fb15 fb15 fb15 fb15 fb15 fb10 ;
|
||||
: .fizzbuzz ( -- ) 1 fb100 drop ;
|
||||
12
Task/FizzBuzz/Haskell/fizzbuzz-7.hs
Normal file
12
Task/FizzBuzz/Haskell/fizzbuzz-7.hs
Normal 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]
|
||||
2
Task/FizzBuzz/K/fizzbuzz-2.k
Normal file
2
Task/FizzBuzz/K/fizzbuzz-2.k
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
fizzbuzz:{:[0=x!15;`0:,"FizzBuzz";0=x!3;`0:,"Fizz";0=x!5;`0:,"Buzz";`0:,$x]}
|
||||
fizzbuzz' 1+!100
|
||||
8
Task/FizzBuzz/K/fizzbuzz-3.k
Normal file
8
Task/FizzBuzz/K/fizzbuzz-3.k
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
fizzbuzz:{
|
||||
v:1+!x
|
||||
i:(&0=)'v!/:3 5 15
|
||||
r:@[v;i 0;{"Fizz"}]
|
||||
r:@[r;i 1;{"Buzz"}]
|
||||
@[r;i 2;{"FizzBuzz"}]}
|
||||
|
||||
`0:$fizzbuzz 100
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
public fun fizzBuzz() {
|
||||
fun fizzBuzz() {
|
||||
for (i in 1..100) {
|
||||
when {
|
||||
i % 15 == 0 -> println("FizzBuzz")
|
||||
7
Task/FizzBuzz/Kotlin/fizzbuzz-2.kotlin
Normal file
7
Task/FizzBuzz/Kotlin/fizzbuzz-2.kotlin
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
fun fizzBuzz() {
|
||||
fun fizzbuzz(x: Int) = if(x % 15 == 0) "FizzBuzz" else x
|
||||
fun fizz(x: Any) = if(x is Int && x % 3 == 0) "Buzz" else x
|
||||
fun buzz(x: Any) = if(x is Int && x.toInt() % 5 == 0) "Fizz" else x
|
||||
|
||||
(1..100).map { fizzbuzz(it) }.map { fizz(it) }.map { buzz(it) }.forEach { println(it) }
|
||||
}
|
||||
11
Task/FizzBuzz/Kotlin/fizzbuzz-3.kotlin
Normal file
11
Task/FizzBuzz/Kotlin/fizzbuzz-3.kotlin
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fun fizzBuzz() {
|
||||
fun fizz(x: Pair<Int, StringBuilder>) = if(x.first % 3 == 0) x.apply { second.append("Fizz") } else x
|
||||
fun buzz(x: Pair<Int, StringBuilder>) = if(x.first % 5 == 0) x.apply { second.append("Buzz") } else x
|
||||
fun none(x: Pair<Int, StringBuilder>) = if(x.second.isBlank()) x.second.apply { append(x.first) } else x.second
|
||||
|
||||
(1..100).map { Pair(it, StringBuilder()) }
|
||||
.map { fizz(it) }
|
||||
.map { buzz(it) }
|
||||
.map { none(it) }
|
||||
.forEach { println(it) }
|
||||
}
|
||||
74
Task/FizzBuzz/MIPS-Assembly/fizzbuzz.mips
Normal file
74
Task/FizzBuzz/MIPS-Assembly/fizzbuzz.mips
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
#################################
|
||||
# Fizz Buzz #
|
||||
# MIPS Assembly targetings MARS #
|
||||
# By Keith Stellyes #
|
||||
# August 24, 2016 #
|
||||
#################################
|
||||
|
||||
# $a0 left alone for printing
|
||||
# $a1 stores our counter
|
||||
# $a2 is 1 if not evenly divisible
|
||||
|
||||
.data
|
||||
fizz: .asciiz "Fizz\n"
|
||||
buzz: .asciiz "Buzz\n"
|
||||
fizzbuzz: .asciiz "FizzBuzz\n"
|
||||
newline: .asciiz "\n"
|
||||
|
||||
.text
|
||||
loop:
|
||||
beq $a1,100,exit
|
||||
add $a1,$a1,1
|
||||
|
||||
#test for counter mod 15 ("FIZZBUZZ")
|
||||
div $a2,$a1,15
|
||||
mfhi $a2
|
||||
bnez $a2,loop_not_fb #jump past the fizzbuzz print logic if NOT MOD 15
|
||||
|
||||
#### PRINT FIZZBUZZ: ####
|
||||
li $v0,4 #set syscall arg to PRINT_STRING
|
||||
la $a0,fizzbuzz #set the PRINT_STRING arg to fizzbuzz
|
||||
syscall #call PRINT_STRING
|
||||
j loop #return to start
|
||||
#### END PRINT FIZZBUZZ ####
|
||||
|
||||
loop_not_fb:
|
||||
div $a2,$a1,3 #divide $a1 (our counter) by 3 and store remainder in HI
|
||||
mfhi $a2 #retrieve remainder (result of MOD)
|
||||
bnez $a2, loop_not_f #jump past the fizz print logic if NOT MOD 3
|
||||
|
||||
#### PRINT FIZZ ####
|
||||
li $v0,4
|
||||
la $a0,fizz
|
||||
syscall
|
||||
j loop
|
||||
#### END PRINT FIZZ ####
|
||||
|
||||
loop_not_f:
|
||||
div $a2,$a1,5
|
||||
mfhi $a2
|
||||
bnez $a2,loop_not_b
|
||||
|
||||
#### PRINT BUZZ ####
|
||||
li $v0,4
|
||||
la $a0,buzz
|
||||
syscall
|
||||
j loop
|
||||
#### END PRINT BUZZ ####
|
||||
|
||||
loop_not_b:
|
||||
#### PRINT THE INTEGER ####
|
||||
li $v0,1 #set syscall arg to PRINT_INTEGER
|
||||
move $a0,$a1 #set PRINT_INTEGER arg to contents of $a1
|
||||
syscall #call PRINT_INTEGER
|
||||
|
||||
### PRINT THE NEWLINE CHAR ###
|
||||
li $v0,4 #set syscall arg to PRINT_STRING
|
||||
la $a0,newline
|
||||
syscall
|
||||
|
||||
j loop #return to beginning
|
||||
|
||||
exit:
|
||||
li $v0,10
|
||||
syscall
|
||||
3
Task/FizzBuzz/MUMPS/fizzbuzz-2.mumps
Normal file
3
Task/FizzBuzz/MUMPS/fizzbuzz-2.mumps
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
fizzbuzz
|
||||
for i=1:1:100 do write !
|
||||
. write:(i#3)&(i#5) i write:'(i#3) "Fizz" write:'(i#5) "Buzz"
|
||||
|
|
@ -2,4 +2,4 @@ multi sub fizzbuzz(Int $ where * %% 15) { 'FizzBuzz' }
|
|||
multi sub fizzbuzz(Int $ where * %% 5) { 'Buzz' }
|
||||
multi sub fizzbuzz(Int $ where * %% 3) { 'Fizz' }
|
||||
multi sub fizzbuzz(Int $number ) { $number }
|
||||
(1 .. 100)».&fizzbuzz.join("\n").say;
|
||||
(1 .. 100)».&fizzbuzz.say;
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
say 'Fizz' x $_ %% 3 ~ 'Buzz' x $_ %% 5 || $_ for 1 .. 100;
|
||||
[1..100].map({[~] ($_%%3, $_%%5) »||» "" Z&& <fizz buzz> or $_ })».say
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
say "Fizz"x$_%%3~"Buzz"x$_%%5||$_ for 1..100
|
||||
say 'Fizz' x $_ %% 3 ~ 'Buzz' x $_ %% 5 || $_ for 1 .. 100;
|
||||
|
|
|
|||
|
|
@ -1,8 +1 @@
|
|||
.say for
|
||||
(
|
||||
(flat ('' xx 2, 'Fizz') xx *)
|
||||
Z~
|
||||
(flat ('' xx 4, 'Buzz') xx *)
|
||||
)
|
||||
Z||
|
||||
1 .. 100;
|
||||
say "Fizz"x$_%%3~"Buzz"x$_%%5||$_ for 1..100
|
||||
|
|
|
|||
8
Task/FizzBuzz/Perl-6/fizzbuzz-6.pl6
Normal file
8
Task/FizzBuzz/Perl-6/fizzbuzz-6.pl6
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
.say for
|
||||
(
|
||||
(flat ('' xx 2, 'Fizz') xx *)
|
||||
Z~
|
||||
(flat ('' xx 4, 'Buzz') xx *)
|
||||
)
|
||||
Z||
|
||||
1 .. 100;
|
||||
14
Task/FizzBuzz/PowerShell/fizzbuzz-4.psh
Normal file
14
Task/FizzBuzz/PowerShell/fizzbuzz-4.psh
Normal 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
|
||||
12
Task/FizzBuzz/Processing/fizzbuzz-3
Normal file
12
Task/FizzBuzz/Processing/fizzbuzz-3
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
for (int i = 1; i <= 100; i++) {
|
||||
if (i % 3 == 0) {
|
||||
print("Fizz");
|
||||
}
|
||||
if (i % 5 == 0) {
|
||||
print("Buzz");
|
||||
}
|
||||
if (i % 3 != 0 && i % 5 != 0) {
|
||||
print(i);
|
||||
}
|
||||
print("\n");
|
||||
}
|
||||
|
|
@ -1,8 +1,8 @@
|
|||
/*REXX program displays numbers 1 ──► 100 for the FizzBuzz problem. */
|
||||
|
||||
do j=1 to 100; z=j /*╔═════════════════════════════╗*/
|
||||
if j//3 ==0 then z='Fizz' /*║ The IFs must be in ║*/
|
||||
if j//5 ==0 then z='Buzz' /*║ ascending order.║*/
|
||||
if j//(3*5)==0 then z='FizzBuzz' /*╚═════════════════════════════╝*/
|
||||
say right(z,8)
|
||||
end /*j*/ /*stick a fork in it, we're done.*/
|
||||
/*REXX program displays numbers 1 ──► 100 (some transformed) for the FizzBuzz problem.*/
|
||||
/*╔═══════════════════════════════════╗*/
|
||||
do j=1 to 100; z= j /*║ ║*/
|
||||
if j//3 ==0 then z= 'Fizz' /*║ The divisors (//) of the IFs ║*/
|
||||
if j//5 ==0 then z= 'Buzz' /*║ must be in ascending order. ║*/
|
||||
if j//(3*5)==0 then z= 'FizzBuzz' /*║ ║*/
|
||||
say right(z, 8) /*╚═══════════════════════════════════╝*/
|
||||
end /*j*/ /*stick a fork in it, we're all done. */
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
/*REXX program displays numbers 1 ──► 100 for the FizzBuzz problem. */
|
||||
|
||||
do n=1 for 100
|
||||
select /*╔═════════════════════════════╗*/
|
||||
when n//15==0 then say 'FizzBuzz' /*║ The WHENs must be in ║*/
|
||||
when n//5 ==0 then say ' Buzz' /*║ descending order║*/
|
||||
when n//3 ==0 then say ' Fizz' /*╚═════════════════════════════╝*/
|
||||
otherwise say right(n,8)
|
||||
end /*select*/
|
||||
end /*n*/ /*stick a fork in it, we're done.*/
|
||||
/*REXX program displays numbers 1 ──► 100 (some transformed) for the FizzBuzz problem.*/
|
||||
/*╔═══════════════════════════════════╗*/
|
||||
do j=1 to 100 /*║ ║*/
|
||||
select /*║ ║*/
|
||||
when j//15==0 then say 'FizzBuzz' /*║ The divisors (//) of the WHENs ║*/
|
||||
when j//5 ==0 then say ' Buzz' /*║ must be in descending order. ║*/
|
||||
when j//3 ==0 then say ' Fizz' /*║ ║*/
|
||||
otherwise say right(j, 8) /*╚═══════════════════════════════════╝*/
|
||||
end /*select*/
|
||||
end /*j*/ /*stick a fork in it, we're all done. */
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
/*REXX program displays numbers 1 ──► 100 for the FizzBuzz problem. */
|
||||
/*REXX program displays numbers 1 ──► 100 (some transformed) for the FizzBuzz problem.*/
|
||||
|
||||
do n=1 for 100; _=
|
||||
if n//3 ==0 then _=_'Fizz'
|
||||
if n//5 ==0 then _=_'Buzz'
|
||||
/* if n//7 ==0 then _=_'Jazz' */ /*◄───note that this is a comment*/
|
||||
say right(word(_ n,1),8)
|
||||
end /*n*/ /*stick a fork in it, we're done.*/
|
||||
do j=1 for 100; _=
|
||||
if j//3 ==0 then _=_'Fizz'
|
||||
if j//5 ==0 then _=_'Buzz'
|
||||
/* if j//7 ==0 then _=_'Jazz' */ /* ◄─── note that this is a comment. */
|
||||
say right(word(_ j,1),8)
|
||||
end /*j*/ /*stick a fork in it, we're all done. */
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*REXX program displays numbers 1 ──► 100 for the FizzBuzz problem. */
|
||||
/* [↓] concise & somewhat obtuse*/
|
||||
do n=1 for 100
|
||||
say right(word(word('Fizz',1+(n//3\==0))word('Buzz',1+(n//5\==0)) n,1),8)
|
||||
end /*n*/
|
||||
/*stick a fork in it, we're done.*/
|
||||
/*REXX program displays numbers 1 ──► 100 (some transformed) for the FizzBuzz problem.*/
|
||||
/* [↓] concise, but somewhat obtuse. */
|
||||
do j=1 for 100
|
||||
say right(word(word('Fizz', 1+(j//3\==0))word('Buzz', 1+(j//5\==0)) j, 1), 8)
|
||||
end /*j*/
|
||||
/*stick a fork in it, we're all done. */
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
1.upto(100) do |n|
|
||||
if (n % 15).zero?
|
||||
puts "FizzBuzz"
|
||||
(1..100).each do |n|
|
||||
puts if (n % 15).zero?
|
||||
"FizzBuzz"
|
||||
elsif (n % 5).zero?
|
||||
puts "Buzz"
|
||||
"Buzz"
|
||||
elsif (n % 3).zero?
|
||||
puts "Fizz"
|
||||
"Fizz"
|
||||
else
|
||||
puts n
|
||||
n
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,13 +1,12 @@
|
|||
#![feature(into_cow)]
|
||||
use std::borrow::IntoCow;
|
||||
|
||||
use std::borrow::Cow;
|
||||
fn main() {
|
||||
for i in 1..101 {
|
||||
println!("{}", match (i%3, i%5) {
|
||||
(0,0) => "FizzBuzz".into_cow(),
|
||||
(0,_) => "Fizz".into_cow(),
|
||||
(_,0) => "Buzz".into_cow(),
|
||||
_ => i.to_string().into_cow(),
|
||||
});
|
||||
let word: Cow<_> = match (i % 3, i % 5) {
|
||||
(0,0) => "FizzBuzz".into(),
|
||||
(0,_) => "Fizz".into(),
|
||||
(_, 0) => "Buzz".into(),
|
||||
_ => i.to_string().into(),
|
||||
};
|
||||
println!("{}", word);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,37 @@
|
|||
fn main() {
|
||||
for i in 1..101 {
|
||||
match (i % 3 == 0, i % 5 == 0) {
|
||||
(true, true) => println!("FizzBuzz"),
|
||||
(true, false) => println!("Fizz"),
|
||||
(false, true) => println!("Buzz"),
|
||||
(false, false) => println!("{}", i),
|
||||
}
|
||||
#![no_std]
|
||||
#![feature(asm, lang_items, libc, no_std, start)]
|
||||
|
||||
extern crate libc;
|
||||
|
||||
const LEN: usize = 413;
|
||||
static OUT: [u8; LEN] = *b"\
|
||||
1\n2\nFizz\n4\nBuzz\nFizz\n7\n8\nFizz\nBuzz\n11\nFizz\n13\n14\nFizzBuzz\n\
|
||||
16\n17\nFizz\n19\nBuzz\nFizz\n22\n23\nFizz\nBuzz\n26\nFizz\n28\n29\nFizzBuzz\n\
|
||||
31\n32\nFizz\n34\nBuzz\nFizz\n37\n38\nFizz\nBuzz\n41\nFizz\n43\n44\nFizzBuzz\n\
|
||||
46\n47\nFizz\n49\nBuzz\nFizz\n52\n53\nFizz\nBuzz\n56\nFizz\n58\n59\nFizzBuzz\n\
|
||||
61\n62\nFizz\n64\nBuzz\nFizz\n67\n68\nFizz\nBuzz\n71\nFizz\n73\n74\nFizzBuzz\n\
|
||||
76\n77\nFizz\n79\nBuzz\nFizz\n82\n83\nFizz\nBuzz\n86\nFizz\n88\n89\nFizzBuzz\n\
|
||||
91\n92\nFizz\n94\nBuzz\nFizz\n97\n98\nFizz\nBuzz\n";
|
||||
|
||||
#[start]
|
||||
fn start(_argc: isize, _argv: *const *const u8) -> isize {
|
||||
unsafe {
|
||||
asm!(
|
||||
"
|
||||
mov $$1, %rax
|
||||
mov $$1, %rdi
|
||||
mov $0, %rsi
|
||||
mov $1, %rdx
|
||||
syscall
|
||||
"
|
||||
:
|
||||
: "r" (&OUT[0]) "r" (LEN)
|
||||
: "rax", "rdi", "rsi", "rdx"
|
||||
:
|
||||
);
|
||||
}
|
||||
0
|
||||
}
|
||||
|
||||
#[lang = "eh_personality"] extern fn eh_personality() {}
|
||||
#[lang = "panic_fmt"] extern fn panic_fmt() {}
|
||||
|
|
|
|||
8
Task/FizzBuzz/SAS/fizzbuzz.sas
Normal file
8
Task/FizzBuzz/SAS/fizzbuzz.sas
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
data _null_;
|
||||
do i=1 to 100;
|
||||
if mod(i,15)=0 then put "FizzBuzz";
|
||||
else if mod(i,5)=0 then put "Buzz";
|
||||
else if mod(i,3)=0 then put "Fizz";
|
||||
else put i;
|
||||
end;
|
||||
run;
|
||||
15
Task/FizzBuzz/Simula/fizzbuzz.simula
Normal file
15
Task/FizzBuzz/Simula/fizzbuzz.simula
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
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 );
|
||||
outimage
|
||||
end;
|
||||
end
|
||||
|
|
@ -1,9 +1,10 @@
|
|||
int main() {
|
||||
for(int i = 1; i < 100; i++) {
|
||||
if(i % 3 == 0) stdout.printf("Fizz");
|
||||
if(i % 5 == 0) stdout.printf("Buzz");
|
||||
if(i % 3 != 0 && i % 5 != 0) stdout.printf("%d", i);
|
||||
stdout.printf("\n");
|
||||
}
|
||||
return 0;
|
||||
for (int i = 1; i <= 100; i++) {
|
||||
if (i % 3 == 0) stdout.printf("Fizz\n");
|
||||
if (i % 5 == 0) stdout.printf("Buzz\n");
|
||||
if (i % 15 == 0) stdout.printf("FizzBuzz\n");
|
||||
if (i % 3 != 0 && i % 5 != 0) stdout.printf("%d\n", i);
|
||||
|
||||
}
|
||||
return 0;;
|
||||
}
|
||||
|
|
|
|||
8
Task/FizzBuzz/ZX-Spectrum-Basic/fizzbuzz.zx
Normal file
8
Task/FizzBuzz/ZX-Spectrum-Basic/fizzbuzz.zx
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
10 DEF FN m(a,b)=a-INT (a/b)*b
|
||||
20 FOR a=1 TO 100
|
||||
30 LET o$=""
|
||||
40 IF FN m(a,3)=0 THEN LET o$="Fizz"
|
||||
50 IF FN m(a,5)=0 THEN LET o$=o$+"Buzz"
|
||||
60 IF o$="" THEN LET o$=STR$ a
|
||||
70 PRINT o$
|
||||
80 NEXT a
|
||||
Loading…
Add table
Add a link
Reference in a new issue