-
-
Save mythz/5691572 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
REM courtesy of https://github.com/nixha | |
@echo off | |
for /L %%I IN (1, 1, 100) DO ( | |
call :OUTPUT %%I | |
) | |
pause | |
exit | |
:OUTPUT | |
set /a A=%1 %% 3 | |
set /a B=%1 %% 5 | |
if "%A%" == "0" ( | |
if "%B%" == "0" ( | |
echo Fizzbuzz | |
) else ( | |
echo Fizz | |
) | |
) else ( | |
if "%B%" == "0" ( | |
echo Buzz | |
) else ( | |
echo %1 | |
) | |
) | |
goto :eof |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;http://alan.dipert.org/post/172774481/fizzbuzz-in-scala-and-clojure | |
(use '[match.core :only (match)]) | |
(doseq [n (range 1 101)] | |
(println (match [(mod n 3) (mod n 5)] | |
[0 0] "FizzBuzz" | |
[0 _] "Fizz" | |
[_ 0] "Buzz" | |
:else n))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Courtesy of Paul G. | |
for (int i = 1; i <= 100; i++) | |
Console.Write(i % 15 == 0 ? "FizzBuzz" : i % 3 == 0 ? "Fizz" : i % 5 == 0 ? "Buzz" : i.ToString()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void main() { | |
for (var i=1; i<=100; i++) | |
print(i % 15 == 0 ? | |
"FizzBuzz" | |
: i % 3 == 0 ? | |
"Fizz" | |
: i % 5 == 0 ? | |
"Buzz" : | |
i); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-module(fizzbuzz). | |
-export([main/0]). | |
main() | |
-> [do(Value) || Value <- lists:seq(1,100)]. | |
do(FizzBuzz) when FizzBuzz rem 15 == 0 | |
-> io:format("FizzBuzz~n"); | |
do(Fizz) when Fizz rem 3 == 0 | |
-> io:format("Fizz~n"); | |
do(Buzz) when Buzz rem 5 == 0 | |
-> io:format("Buzz~n"); | |
do(Number) | |
-> io:format("~p~n", [ Number ]). | |
%% Another implementation at http://en.literateprograms.org/FizzBuzz_(Erlang) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let (wr : string -> unit) = System.Console.WriteLine | |
let (|Fizz|Buzz|FizzBuzz|Other|) input = | |
if input % 15 = 0 then FizzBuzz | |
elif input % 3 = 0 then Fizz | |
elif input % 5 = 0 then Buzz | |
else Other | |
[1..100] |> Seq.iter (fun n -> | |
match n with | |
| Fizz -> wr "Fizz" | |
| Buzz -> wr "Buzz" | |
| FizzBuzz -> wr "FizzBuzz" | |
| Other -> wr(n.ToString()) | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Taken and then indented from http://play.golang.org/p/0fG1oKhdB9 | |
package main | |
func main(){ | |
for i:=1;i<101; | |
i++{n,m:=i%3,i%5 | |
if n*m>0 { | |
print(i) | |
} else { | |
if n==0 {print("Fizz")} | |
if m==0 {print("Buzz")} | |
} | |
println()} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- taken from http://freshbrewedcode.com/calvinbottoms/2012/02/25/fizzbuzz-in-haskell/ | |
[max(show x)(concat[n|(f,n)<-[(3,"Fizz"),(5,"Buzz")],mod x f==0])|x<-[1..100]] | |
-- a more readable solution, taken from https://gist.github.com/NeilRobbins/5190365 | |
divides d n = rem n d == 0 | |
fizzbuzz n | divides 15 n = "fizzbuzz" | |
| divides 3 n = "fizz" | |
| divides 5 n = "buzz" | |
| otherwise = show n | |
map fizzbuzz [0..] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// courtesy of https://github.com/nixha | |
public static void main(String[] args) { | |
for (int i = 0; i < 100; System.out.println(++i % 3 == 0 ? i % 5 == 0 ? "Fizzbuzz" : "Fizz" : i % 5 == 0 ? "Buzz" : i)); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// taken from https://gist.github.com/abreslav/5203175 | |
fun Int.divides(d: Int) = this % d == 0 | |
fun fizzbuzz(n: Int) = when { | |
n divides 15 -> "fizzbuzz" | |
n divides 3 -> "fizz" | |
n divides 5 -> "buzz" | |
else -> "$n" | |
} | |
fun result(max: Int) = (0..max) map { n -> fizzbuzz(n) } | |
// Optionally, to print it out | |
fun main(args: Array<String>) { | |
println(result(100)) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@(1..100) | % { | |
if ($_ % 15 -eq 0) {"FizzBuzz"} | |
elseif ($_ % 5 -eq 0) {"Buzz"} | |
elseif ($_ % 3 -eq 0) {"Fizz"} | |
else { $_ } | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(1..100).each do |n| | |
mod3, mod5 = n % 3, n % 5 | |
if (mod3 * mod5 > 0) | |
puts n | |
else | |
out = "" | |
out += "Fizz" if (mod3 == 0) | |
out += "Buzz" if (mod5 == 0) | |
puts out | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// http://alan.dipert.org/post/172774481/fizzbuzz-in-scala-and-clojure | |
(1 to 100) map { x => | |
(x % 3, x % 5) match { | |
case (0,0) => "FizzBuzz" | |
case (0,_) => "Fizz" | |
case (_,0) => "Buzz" | |
case _ => x toString | |
} | |
} foreach println |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment