DEV Community

Discussion on: Unconditional Challenge: FizzBuzz without `if`

Collapse
 
kallmanation profile image
Nathan Kallman

It's a nice answer! It satisfies the normal rules (no if or ?:)

Thanks for taking the time to submit a solution!

Collapse
 
vidit1999 profile image
Vidit Sarkar

Thanks for the reply. I think re-submission is also allowed. So, here is a C++ solution, which again, may not satisfy all your conditions.

string fizzbuzz(int n){
    string num_string = to_string(n);

    string all_options[5][3] = {
        {"FizzBuzz" ,"Buzz" , "Buzz"},
        {"Fizz" , num_string, num_string},
        {"Fizz" , num_string, num_string},
        {"Fizz" , num_string, num_string},
        {"Fizz" , num_string, num_string}
    };

    return all_options[n%5][n%3];
}
Thread Thread
 
kallmanation profile image
Nathan Kallman

Well done! I think you've got a solution