Over a million developers have joined DZone.

Code Challenge Series

Fizz Buzz Code Golf. The objective: solve the challenge in the language of your choice in the least number of characters possible.

· Java Zone

Check out this 8-step guide to see how you can increase your productivity by skipping slow application redeploys and by implementing application profiling, as you code! Brought to you in partnership with ZeroTurnaround.

I imagine you've heard of the Fizz Buzz interview question, it's not a difficult problem but today we're going to put a slightly different take on it. It originates from a children's game played in UK schools.

These children count aloud and for every number divisible by 3 they say "Fizz" and for every number divisible by 5 they say "Buzz" and when divisible by both they say "Fizz-Buzz".

Here are the requirements:

  • The program must count from 1 to 100 and output the number unless divisible by 3 or 5.

  • If the number is divisible by 3 the program should output the word "Fizz"

  • If the number is divisible by 5 it should output the word "Buzz"

  • When divisible by both 3 and 5 the program should output "Fizz-Buzz"

All very simple, but now the challenge is writing the shortest program possible, after all this is golf and there are no handicaps.

The rules are simple, the program should resolve the above problem in any language in the least characters possible.

In next week's edition of code challenges we will announce the winner of this week's challenge.

The Java Zone is brought to you in partnership with ZeroTurnaround. Check out this 8-step guide to see how you can increase your productivity by skipping slow application redeploys and by implementing application profiling, as you code!

Topics:
code golf

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}