</2011><2012>

</2011><2012>

In the beginning of every year I say to myself never regret your mistakes just learn from them, start the new year with fresh thoughts, new hopes, new dreams, being optimistic, and keep on trying till I reach the highest…

Code Kata: Fizz Buzz Game

Code Kata: Fizz Buzz Game

I stared to practice recently after reading more about how practicing is important for programmer to become professional and one way of practicing is Coding Kata. I found a lot of problem to implement to practice and perform coding kata.

This post I’ll talk about Fizz Buzz Game a.k.a. Bizz Buzz Game, it’s numerical/math game, if the number is divisible by 3 replace it with fizz, or if number divisible by 5 replace it with buzz, or if number is divisible by 3 and 5 replace it with fizzbuzz. For example if we count from 1 to 20 it’ll be like this: 1, 2, fizz, 4, buzz, fizz, 7, 8, fizz, buzz, 11, fizz, 13, 14, fizzbuzz, 16, 17, fizz, 19, buzz.

So how to code this game:

First I thought I can solve this game by:

If (this number is divisible by 3 and not divisible by 5)  return fizz

else if (this number is not divisible by 3 and divisible by 5)  return buzz

else if (this number is divisible by 3 and divisible by 5)  return buzzfizz

else if(this number is not divisible by 3 and not divisible by 5)  return the number

But when I look at the code I feel like I can optimize it more by remove the and between two logical conditions, as the following.

After observing the results, I found that fizzbuzz only appears when the number is divisible by 15, so I rewrite my pseudocodecode

If (this number is divisible by 15)  return buzfizz

else if (this number is divisible by 3)  return fizz

else if (this number is divisible by 5)  return buzz

else  return the number

This Coding Kate done, I’ve enjoyed it as taook me to collage day’s when having fun solving small problems, I hope you enjoyed it as well. See you next Coding Kata.

Coding Kata

Coding Kata

  Recently I’m reading Uncle Bob‘s Clean Coder book and I read about how a professional programmer must always practice, like professional musicians, professional football player, and professional martial arts player. I’m learning  how to play electric guitar, you need to start slowly “slow…