FizzBuzz in ten languages
iolivia.me
FizzBuzz in ten languages
1–10 of 103 posts
Re: FizzBuzz in ten languages
#2Re: FizzBuzz in ten languages
#3Java, VBA, php, cobol, forth, C++, brainfuck, python, Groovu, BASIC, JavaScript, CoffeeScript, sh, PowerShell, Clojure, Ruby, C#, Haskell, ABAP, Lua, Matlab, Common Lisp, Oracle PL/SQL, Scala, F#, Bash, C, LOLCODE, golang, Enterprise Java, MySQL, Visual FoxPro, Perl, shakespeare
Of course, if you want it in Malboge [1], you can refer to a prior HN discussion [2] of FizzBuzz in multiple languages.
[0] http://wiki.c2.com/?FizzBuzzTest
Re: FizzBuzz in ten languages
#4The Rust example looks a bit strange, since you're matching on a variable, but don't actually use it.
Instead, you could write the match like this:
let div_by_three = x % 3 == 0;
let div_by_five = x % 5 == 0;
match (div_by_three, div_by_five) {
(true, true) => println!("FizzBuzz"),
(true, false) => println!("Fizz"),
(false, true) => println!("Buzz"),
_ => println!("{}", x),
}
...or even like this: match (x % 3, x % 5) {
(0, 0) => println!("FizzBuzz"),
(0, _) => println!("Fizz"),
(_, 0) => println!("Buzz"),
_ => println!("{}", x),
}
Furthermore, inclusive ranges can be written like this: for x in 1..=100 {Re: FizzBuzz in ten languages
#5Re: FizzBuzz in ten languages
#6Re: FizzBuzz in ten languages
#7Personally I prefer a fizz buzz that doesn’t make them variables. The loop is so small and it’s obviously never “hot” enough code to make it worthwhile to pull the variables out. It looks like over-optimization to me.
Re: FizzBuzz in ten languages
#8Re: FizzBuzz in ten languages
#9If you like this may I also recommend [0] which has fizzbuzz in: Java, VBA, php, cobol, forth, C++, brainfuck, python, Groovu, BASIC, JavaScript, CoffeeScript, sh, PowerShell, Clojure, Ruby, C#, Haskell, ABAP, Lua, Matlab, Common Lisp, Oracle PL/SQL, Scala, F#, Bash, C, LOLCODE, golang, Enterprise Java, MySQL, Visual FoxPro, Perl, shakespeare Of course, if you want it in Malboge [1], you can refer to a prior HN discu…
(d 3 "Fizz" d 5 "Buzz")
becomes (d 3 "Fizz" d 5 "Buzz" d 13 "Woof")
eta: And just below it is a similar solution in Python. Cool!