FizzBuzz


 
Try solving this very simple program which is asked in many interviews, especially to testers who use a lot of scripting in automation:

  • 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 are multiples of both three and five print “FizzBuzz”
This is also a game played in the pubs , where players generally sit in a circle. The player designated to go first says the number "1", and each player thenceforth counts one number in turn. However, any number divisible by three is replaced by the word fizz and any divisible by five by the word buzz. Numbers divisible by both become fizz buzz. A player who hesitates or makes a mistake is either eliminated or must pay a forfeit, such as taking a drink.


 Most tester's who know to code are not able to solve this simple problem. Out of every ten automation engineers i have interviewed 9 weren't able to solve this simple problem.

---------------------------------------------------------------------------------------------------------------
Lets look at the simple algo:

For n = 1 To 100
 Select Case 0
   Case n Mod 15
      f = "FizzBuzz"
   Case n Mod 3
      f = "Fizz"
   Case n Mod 5
      f = "Buzz"
   Case Else
      f = n
 End Select
 Print f
Next n

Comments

Popular posts from this blog

Software Testing @ Microsoft

Trim / Remove spaces in Xpath?