Questions tagged [fizzbuzz]

a game, algorithm and a common programming task of replacing any number divisible by three with the word "fizz", and any number divisible by five with the word "buzz"

Fizzbuzz is a game used to teach children division. Implementing an algorithm for that game is sometimes used as an interview task.

https://en.wikipedia.org/wiki/Fizz_buzz

290 questions
7
votes
1 answer

FizzBuzz program seems slow: why?

[ANSWER] Go doesn't buffer stdout. Switching to a buffered version and manually flushing brings it much closer to what you would expect. Avoiding fmt makes it run as fast as you like. I'm trying to write the FizzBuzz program in Go. func main() { …
Joseph
  • 73
  • 4
5
votes
8 answers

fizzbuzz in haskell?

I'm trying to write 'fizzbuzz' in haskell using list comprehensions. Why doesn't the following work, and how should it be? [ if x `mod` 5 == 0 then "BUZZFIZZ" if x `mod` 3 == 0 then "BUZZ" if x `mod` 4 == 0 then "FIZZ" | x <- [1..20], x…
Paul J
  • 777
  • 2
  • 8
  • 18
5
votes
10 answers

FizzBuzz using JDK8 Lambda

Just want to see by JDK8 lambda how small the program can be, my approach is using a result builder: IntStream.rangeClosed(0 , 100).forEach(i ->{ StringBuffer bfr= new StringBuffer(); if(i % 3 == 0 ) bfr.append("Fizz"); …
Seng Zhe
  • 613
  • 1
  • 11
  • 21
5
votes
3 answers

Confusing output on fizzbuzz with switch case statement

Here the famous "fizz buzz" program in Go using switch/case and if/else conditionals. The problem is that using switch/case is generating unexpected output while if/else (with same conditions) works fine. I know that switch/case in golang is…
4
votes
2 answers

FizzBuzz Conundrum

The FizzBuzz question is a very classical interview question asked in multiple interviews all around the world. There are many ways to do it in different languages. But in most general terms it definitely involves using 3 or 4 if/else if loops.There…
shd293
  • 97
  • 1
  • 8
4
votes
4 answers

Grouping of FizzBuzz numbers

I am trying to code FizzBuzz problem in Java8. It is working fine and I am getting desired output. For the number divisible by "3", it should return "Fizz", for the number divisible by "5", it should return "Buzz" and for the number divisible by…
Achal
  • 133
  • 2
  • 12
4
votes
1 answer

Fizz-Buzz at C++ compile time

We talked about the “fizz buzz” programming test today, I thought about implementing this with in C++ but with meta-programming. Ideally it would generate the output already during compilation time. My current code uses templates, but it still has…
Martin Ueding
  • 8,245
  • 6
  • 46
  • 92
4
votes
8 answers

FizzBuzz list comprehension

I was messing around with some different fizz buzz scripts as I learn python. I came across this one which works great but I can't decipher how it works. I know how the normal fizz buzz works with a for loop and "if i % 3 == 0 and i % 5 == 0". What…
Neal
  • 104
  • 2
  • 9
4
votes
2 answers

Fizzbuzz (Turning my output to a string?)

New here and hoping I can help as much as I am helped. Basically, I have been tasked with writing a fizzbuzz program in Python and so far so good except for some feedback I received. Now I have to ensure that the output of my program comes across…
Buggs
  • 41
  • 4
4
votes
1 answer

Hexadecimal based FizzBuzz in Python

I'm sure that for most of you should be familiar with what FizzBuzz is. For those who don't know what I'm stating here. Here is what FizzBuzz is: Write a program that prints the numbers from 1 to 100. But for multiples of three print "Fizz" instead…
User1453
  • 63
  • 1
  • 7
4
votes
5 answers

Find if a number is divisible by 3 or 5 (FizzBuzz)

How do I change the output depending on whether or not it is divisible by 3 or 5? If it is divisible by 3, I want to show "rock" and if it's divisible by 5 I want to show "star" (similar to in FizzBuzz). If both, they'll see both. Here's my…
Corey Blinks
  • 57
  • 1
  • 1
  • 4
4
votes
6 answers

Why does it work?

So I'm learning Python and working through a list of program ideas. Of course I wrote the obligatory FizzBuzz, which worked, but was basically if elif else blablabla. I googled it to see if there are other ways and found this dank one-liner: for i…
4
votes
2 answers

fizzbuzz in Python using random, how does it work?

I am having a hard time figuring out how the code below works: import random for i in range(0, 100): if not i % 15: random.seed(1178741599) print [i+1, "Fizz", "Buzz", "FizzBuzz"][random.randint(0,3)] I understand that when i is…
Skiptomylu
  • 964
  • 1
  • 13
  • 21
4
votes
1 answer

Invalid indirect of type func (int) string

I'm getting stucked with the following error: ./main.go:76: invalid indirect of Fizzbuzz (type func(int) string) I understand that the Fizzbuzz function does not satisfy the writeString. My intuition is telling me that this is probably because I…
Alex
  • 367
  • 2
  • 4
  • 14
4
votes
3 answers

FizzBuzz with Active Patterns

I'm trying to understand Active Patterns, so I'm playing around with FizzBuzz: let (|Fizz|_|) i = if i % 3 = 0 then Some Fizz else None let (|Buzz|_|) i = if i % 5 = 0 then Some Buzz else None let (|FizzBuzz|_|) i = if i % 5 = 0 && i % 3 = 0 then…
Nick Heiner
  • 119,074
  • 188
  • 476
  • 699
1
2
3
19 20