Fizz Buzz Problem

This is the best solution I could find to this problem. It would be really great if you guys post your solutions too! :smiley:

def fizzbuzz():
        arr = ("", "", "Fizz", "", "Buzz", "Fizz", "", "", "Fizz", "Buzz", "", "Fizz", "", "", "FizzBuzz")
        arr_index = 0

        for i in range(1, 101):
                if arr[arr_index] == "":
                        print (i)
                else:
                        print(arr[arr_index])
                arr_index += 1
                if arr_index == 15:
                    arr_index = 0
1 Like
def fizz_buzz(limit, num_one, num_two):
    for i in range(1, limit):
        arg_one = ""
        arg_two = ""
        if not (i%num_one == 0) and not (i%num_two == 0):
            arg_one = str(i)
        else:
            if i % num_one== 0:
                arg_one = "Fizz"
            if i % num_two == 0:
                arg_two = "Buzz"
        print_output(arg_one, arg_two)

def print_output(fizz="", buzz=""):
    print("{}{}".format(fizz,buzz))

Here is my take on the problem :slight_smile:
EDITS: code formatting

1 Like

void fizzbuzzcount(int fizz,int buzz,int fizzbuzz, int counter)
{
if(counter==100)
return;
if(fizzbuzz==15){
fizzbuzz=0;
cout<<“fizzbuzz”;
}else if(fizz==3){
fizz=0;
cout<<“fizz”;
}else if(buzz==5){
buzz=0;
cout<<“buzz”;
}else{
cout<<counter;
}

fizzbuzzcount(fizz+1,buzz+1,fizzbuzz+1,counter+1);

}

int main(){
fizzbuzzcount(0,0,0,0);
}

1 Like

Usually, in most programming languages, the counter solution is best (memory + speed wise).

1 Like