Live data from Hacker News

FizzBuzz in ten languages

iolivia.me

1–10 of 103 posts

Re: FizzBuzz in ten languages

#3
If 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 discussion [2] of FizzBuzz in multiple languages.

[0] http://wiki.c2.com/?FizzBuzzTest

[1] https://en.wikipedia.org/wiki/Malbolge

[2] https://news.ycombinator.com/item?id=4921651

Re: FizzBuzz in ten languages

#4
Crossposting my comment from the blog:

The 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

#6
Personally 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

#7
post #6

Personally 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.

I agree, but for different reasons. I have seen a lot of code start with variables like `divisible_by_three`, only to have the requirements change to check division by 4, but programmers being too lazy to update the variable name as well.

Re: FizzBuzz in ten languages

#9

If 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…

The "Haskell implementation using monoids" on this page is the only solution I've seen where adding a new behavior (e.g. "FizzBuzzWoof") only requires a modification in one spot.

  (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!
Post reply on HN