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
4
votes
1 answer

Optimizing DCPU-16 FizzBuzz

I tried to implement FizzBuzz in DCPU-16. I use this web emulator: http://mappum.github.com/DCPU-16/ (repository: https://github.com/mappum/DCPU-16). It stops before the end of the loop. Why? How can I optimize it? I'm a high level language…
halukul
  • 65
  • 4
3
votes
1 answer

Is there a shorthand way to print a different variable if one variable is empty in C++?

I'm trying to write a minified FizzBuzz program in C++ as I am just now learning it. I wondering if there's a shorthand way to say "If this string exists, return this string, otherwise, return this next part" In JavaScript, using the || operator…
Samathingamajig
  • 11,839
  • 3
  • 12
  • 34
3
votes
1 answer

C++ lambda and inlined fizzbuzz

Heoi, I've seen a C++ talk where someone made a lambda fizzbuzz implementation. This is not it! Not even close to it! My question is, why can't I use the ostream& auto fizz = [](int& x, std::ostream& os) { x % 3 == 0 ? os << "fizz" : 0; }; auto…
FistyTries
  • 109
  • 11
3
votes
3 answers

Another FizzBuzz solution

I was in a job interview and was asked to solve FizzBuzz with PHP. Write a program that prints the numbers from 1 to 100. But for multiples of three print “Fizz” instead of the number and for the multiples of five print “Buzz”. For numbers which…
Madian Malfi
  • 595
  • 1
  • 8
  • 26
3
votes
3 answers

If...else statements to check for NaN and empty string not working in JavaScript

I refactored FizzBuzz using functions and everything is working great except for two if..else statements in the function meant to validate the user's input (validateValue). I want to alert users that empty strings, decimals and NaN are not allowed.…
ev662
  • 69
  • 1
  • 10
3
votes
5 answers

Fizzbuzz program in C

Okay, this really isn't as much a fizzbuzz question as it is a C question. I wrote some simple code in C for printing out fizzbuzz as is required. #include int main(void) { int n = 30; int i; for (i = 1; i<=n; i++) …
Silver
  • 1,327
  • 12
  • 24
3
votes
2 answers

Does the Java optimizer memoize calculated values?

Which fizzbuzz implementation is more efficient? public static void fizzBuzz1(int n) { boolean fizzed, buzzed; for(int i = 1; i <= n; i++) { fizzed = buzzed = false; if(i % 3 == 0) …
Celeritas
  • 14,489
  • 36
  • 113
  • 194
3
votes
5 answers

C / C++ Interview: Code Optimization

I had an interview today. This question was to optimize the code below. if we will see the code below after for loop there are four steps of "if-else" follows. So, interviewer asked me optimize it to 3 if-else line. I have tried a lot. But could not…
Rasmi Ranjan Nayak
  • 11,510
  • 29
  • 82
  • 122
3
votes
1 answer

Ruby Strings - difference between << and +=

Running the method fizzbuzz1 yields a 100 member list of numbers 1 to 100, where each multiple of 3 is replaced by "fizz", each multiple of 5 by "buzz", and each multiple of both 3 and 5 by "fizzbuzz": def fizzbuzz1() result = Array.new(100, "") …
polpetti
  • 787
  • 7
  • 21
3
votes
2 answers

FizzBuzz Disaster

I wanted to test my C++ skills by hammering out a quick fizzbuzz application. The code for it is posted below. However, when I run this application, something crazy occurs. Here's my code: #include #include using namespace…
Nathan
  • 2,093
  • 3
  • 20
  • 33
3
votes
1 answer

Of the two solutions to FizzBuzz in clojure, why is one faster?

Of the two solutions to FizzBuzz in clojure, why is the first one faster? ; #1 (defn fizzbuzzer [z] "fizzbuzz checker." (let [fizz? (zero? (rem z 3)) buzz? (zero? (rem z 5)) fizzbuzz? (and fizz? buzz?)] (cond…
2
votes
10 answers

Codecademy FizzBuzz app, stuck on step 1

Here's my code for Codecamedy's FizzBuzz lesson var i; for ( i = 1; i > 20; i++ ) { "hello" if ( i % 3 === 0 ) { if ( i % 5 === 0 ) { "FizzBuzz"; } else { "Fizz"; } } else if ( i % 5 === 0 ) { "Buzz"; } …
mrdavidjcole
  • 1,862
  • 3
  • 15
  • 14
2
votes
1 answer

END-PERFORM needed, but also not needed?

COBOL code with terminal errors The error messages are: fizzbuzz.cob:12: error: PERFORM statement not terminated by END-PERFORM fizzbuzz.cob:18: error: syntax error, unexpected END-PERFORM I'm getting a compile error with this program because it…
Durandal
  • 23
  • 3
2
votes
5 answers

Modifying a function without losing sense

Edit: I think I need to be more precise, the code itself is good but I need to modify it not to have a block with more than 3 branches. For instance, one could separate it by doing multiple functions I am trying to do the Fizzbuzz, my code is right…
2
votes
2 answers

How to select all values from an array or list?

I'm super new to programming and I'm wondering how to tackle one of the most basic problems out there-- the "FizzBuzz" thing. I'm doing this in Groovy. I have a pretty specific idea of how I want the code to be constructed, but I can't for the life…
Ben
  • 23
  • 1
  • 3
1 2
3
19 20