Also we have the teapot, hello world, Foo Bar
What are some others?
31–40 of 103 posts
Also we have the teapot, hello world, Foo Bar
What are some others?
I've been looking for an example that shows how pattern matching can make code much both compact and readable. I think this does nicely. Here's an example in Scala: (1 to 100).map(i => (i % 3, i % 5) match { case (0, 0) => "FizzBuzz" case (0, _) => "Fizz" case (_, 0) => "Buzz" case _ => s"$i" }).foreach(println) Compare that to the rest of the examples on the page. The only one that comes close in either readability…
The Haskell example is quite similar to the Scala/Rust example as well. I guess you could rewrite the Haskell version to match your Scala version pretty closely as well if you prefer doing the tuple construction and then matching on the tuple, like in your Scala version, instead of doing it directly inside the pattern match. Something like this, with the caveat that I haven't done any proper coding in Haskell in year…
Why or how did fizzbuzz earn its place in lore? I looked at Wikipedia and it didn't seem to go into detail. Also we have the teapot, hello world, Foo Bar What are some others?
Atwood referenced Imran Ghory who seems to have originated the test.
Why or how did fizzbuzz earn its place in lore? I looked at Wikipedia and it didn't seem to go into detail. Also we have the teapot, hello world, Foo Bar What are some others?
The functional why was as a filter for eliminating impostors. At the time it was new, no one could look up the answers for it, because it was such an arbitrary problem. Now, it's just a curiosity.
Someone should make a tabletop game inspired by FizzBuzz. Or maybe a card game. It should have "bins" as a mechanic. Maybe change the name to include "bin" in it. Throw in 60's science fiction TV aesthetics and 30's gangsters.
Your bash example could be a little cleaner. Since 0 is truthy in bash and [ `expr something` ] is, for most purposes, (( )). for i in {1..100}; do if (( $i % 3 && $i % 5 )); then echo FizzBuzz elif (( $i % 3 )); then echo Fizz elif (( $i % 5 )); then echo Buzz else echo $i fi done Bash also has a decently powerful matching statement so you can do something similar to the rust example. for i in {1..100}; do case "$((…
HNY! (:
Someone should make a tabletop game inspired by FizzBuzz. Or maybe a card game. It should have "bins" as a mechanic. Maybe change the name to include "bin" in it. Throw in 60's science fiction TV aesthetics and 30's gangsters.
The best i can come up with is a Rummy variant. If you need 30s gangsters to play Rummy: The Factor Baron then I have a kickstarter for you...
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), } ..…
Did the author change it?
Edit: just saw the comments on the article. Yes, she did.
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!
for n in range(1, 101):
print(n, end='\r')
if n % 3 == 0:
print("Fizz", end='')
if n % 5 == 0:
print("Buzz", end='')
print()