Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers AppGameKit Corner / Do the FizzBuzz!

Author
Message
Dybing
13
Years of Service
User Offline
Joined: 12th Sep 2011
Location: Bergen, Norway
Posted: 23rd Jun 2016 19:09 Edited at: 23rd Jun 2016 19:10
A popular drinking game - and an entry level test of ones ability solve a problem by hammering out a little piece of code.

Premise is simple. In the drinking game, one take turn counting up from 1 to x. Every time one reach a number that is divisible by 3, one says Fizz instead. If divisible by 5, one says Buzz. If divisible by both 3 and 5, one says FizzBuzz. Get it wrong, empty a drink.

Now make a piece of code that counts from 1 to 100 and displays it as text on screen, but follow the rules above. So, it'd be counting 1, 2, Fizz, 4, Buzz, 6, 7 etc. Any solution will do, but if you figure it out and get correct results within 5 minutes (without cheating), give yourself a pat on the back - you're thinking like a programmer
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 23rd Jun 2016 20:46 Edited at: 23rd Jun 2016 20:47
I like a short challenge

Here is my entry, I'd love to see somebody make an improved algorithm for setting the fizz/buzz/fizzbuzz/number.
No cheating, create your own before checking mine. I have documented for the benefit of beginners.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
Dybing
13
Years of Service
User Offline
Joined: 12th Sep 2011
Location: Bergen, Norway
Posted: 23rd Jun 2016 21:02
Love the extra flair in the presentation
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 24th Jun 2016 07:09
Challenge 2 should be writing the solution while drunk.
In the UK we call the "adult" drinking version "Fuzzy Duck". Try it and you will soon work out why.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
Dybing
13
Years of Service
User Offline
Joined: 12th Sep 2011
Location: Bergen, Norway
Posted: 24th Jun 2016 13:31 Edited at: 25th Jun 2016 10:55
Don't remember what we call that game here in Norway - hey, I was drunk last time I played it

I'd think there would be a few more takers by now though. It's a great little challenge that requires little more than knowing recursion and conditionals.

I thought about doing the Decimal to Roman numerals translator next, 1 through 100. But that is an order or two of magnitude more complex.

Oh, by the way, my code for FizzBuzz (anyone still wanting to do this, no cheating):



No nice text effects though. Just boring old Print()
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 25th Jun 2016 07:37
I just learned something new
I didn't know you could use SELECT in that way.
A much more elegant solution. The only thing I would change is swapping the 3 and the 5 CASE statements over. There are more 3s than 5s, so it will exit the selection quicker, more often.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt

Login to post a reply

Server time is: 2024-11-23 23:07:18
Your offset time is: 2024-11-23 23:07:18