r/deftruefalse • u/jP_wanN • May 26 '16
Implement FizzBuzzBazz
The FizzBuzzBazz challenge
Create a program that prints the first N entries of the FizzBuzzBazz sequence to stdout, where any (hardcoded) N between 0 and at least 2'147'483'647 (the biggest number representable by a signed 32bit integer).
The FizzBuzzBazz sequence is a simple extension of the FizzBuzz sequence. An easy implementation to get one of its elements (which obviously isn't allowed here, see rules below) would be:
function fizz_buzz_bazz(i) {
var str = "";
if (i % 3 == 0)
str += "Fizz";
if (i % 5 == 0)
str += "Buzz";
if (i % 7 == 0)
str += "Bazz";
return str || i.toString();
}
Rules
- No mutation allowed (hence the above implementation is not allowed)
- You're only allowed to call a single function
with side effectsthat does IO- Import statements don't count in case they are ordinary functions in the language of your choice
- You're allowed to call one extra function
with side effectsthat does IO if you use it to read N at runtime instead of hardcoding it - You can use the standard library of the language you use, as well as well-known third-party libraries, but no obscure tiny libraries that are made to solve exactly this problem
- Reminder: this sub has the rule to not submit any idiomatic code
Bonus challenges
- Implement the logic of this program as a C++ template with N being the template parameter
- Make all of your own functions return abnormally (e.g. throw an exception)
- Call one less function
with side effectsthat does IO than allowed
10
Upvotes
View all comments
Show parent comment
1
u/ultrasu May 26 '16
To be fair, I mostly use C for FFIs with other languages. Rust does look great, been meaning to learn it for months now, will hopefully have the time this summer.
I did initially try to come up with a shitty implementation in Haskell or Lisp, but not sure how without violating the no-mutation rule. Easiest way to misuse a functional languages is to abuse mutability. I'm pretty sure you can write some really weird FizzBuzzBazz implementation using Haskell's type system and/or Template Haskell and/or Control.Arrow, though that's also a bit too advanced for me at the moment.