Jump to content

Recommended Posts

I know fizzbuzz has been mentioned a few times in the forum; I just saw a Youtube video from Tom Scott about it. I paused the video before he discussed his solution and came up with my own first.  My first version already had some modularity in mind, but I decided to go further and make one with maximal modularity in mind--multiple words and multiple round conditions. 

To keep things simple, the only requirement is that the words and rounds have to be defined in such a way that the expected order is correct (word order and round order). It was a simple but fun exercise. 

Here is the video if anyone is interested:



And here is my solution:

Const Enum $UBOUND_ROWS = 1, $UBOUND_COLUMNS        ;Constants for UBOUND function parameters
Const $VERBSANDROUNDS[][] = [["Fizz", 3],["Buzz", 5],["Pop", 9, 11]]        ;Verb List - Two-Dimension Array

For $iRound = 1 to $ROUNDS      ;For each round
    Local $sRoundOutput = ""        ;Initialize blank string
    For $iVerb = 0 To $VERBS        ;For each Verb Word
        For $iVerbRound = 1 To $VERBROUNDS      ;For each Verb Round to Evaluate
            If Not Mod($iRound, $VERBSANDROUNDS[$iVerb][$iVerbRound]) Then $sRoundOutput &= $VERBSANDROUNDS[$iVerb][$VERBWORD]      ;If Round is Divisble by Verb Round, append Verb Word to string
    If Not $sRoundOutput Then $sRoundOutput = $iRound   ;If string is blank (no verb words) set string value to round number
    ConsoleWrite($sRoundOutput & @CRLF)     ;Output string



Edited by spudw2k
made the solution code more meaningful / readable
Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...