spudw2k Posted April 18, 2021 Posted April 18, 2021 (edited) 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: Spoiler And here is my solution: Spoiler 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 Const $ROUNDS = 100, $VERBWORD = 0, $VERBS= UBound($VERBSANDROUNDS,$UBOUND_ROWS) - 1, $VERBROUNDS = UBound($VERBSANDROUNDS, $UBOUND_COLUMNS) - 1 ;Other Constants 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 Next Next If Not $sRoundOutput Then $sRoundOutput = $iRound ;If string is blank (no verb words) set string value to round number ConsoleWrite($sRoundOutput & @CRLF) ;Output string Next Edited April 21, 2021 by spudw2k made the solution code more meaningful / readable Spoiler Things I've Made: Always On Top Tool ◊ AU History ◊ Deck of Cards ◊ HideIt ◊ ICU ◊ Icon Freezer ◊ Ipod Ejector ◊ Junos Configuration Explorer ◊ Link Downloader ◊ MD5 Folder Enumerator ◊ PassGen ◊ Ping Tool ◊ Quick NIC ◊ Read OCR ◊ RemoteIT ◊ SchTasksGui ◊ SpyCam ◊ System Scan Report Tool ◊ System UpTime ◊ Transparency Machine ◊ VMWare ESX Builder Misc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retrieve SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose Array Projects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalc Cool Stuff: AutoItObject UDF ◊ Extract Icon From Proc ◊ GuiCtrlFontRotate ◊ Hex Edit Funcs ◊ Run binary ◊ Service_UDF
AlchemistZim Posted December 10, 2022 Posted December 10, 2022 Why Not This Spoiler For $i = 1 to 101 $String = "" If Mod($i, 3) = 0 Then $String = $String & "Fizz" If Mod($i, 5) = 0 Then $String = $String & "Buzz" If Not $String = "" Then ConsoleWrite(@CRLF & $i & " - " & $String) Next
spudw2k Posted December 11, 2022 Author Posted December 11, 2022 Close, but notice that your logic only outputs when fizz, buzz, or fizzbuzz are present. Also, when fizz/buzz/fizzbuzz are output, there should not be an integer displayed. Take note of the output in the video here: Spoiler My code is meant to be more modular/flexible so that it could accommodate different conditions, but I suppose it is a fair criticism that if the running conditions are set in stone, this doesn't add any value. It was just a fun exercise. Spoiler Things I've Made: Always On Top Tool ◊ AU History ◊ Deck of Cards ◊ HideIt ◊ ICU ◊ Icon Freezer ◊ Ipod Ejector ◊ Junos Configuration Explorer ◊ Link Downloader ◊ MD5 Folder Enumerator ◊ PassGen ◊ Ping Tool ◊ Quick NIC ◊ Read OCR ◊ RemoteIT ◊ SchTasksGui ◊ SpyCam ◊ System Scan Report Tool ◊ System UpTime ◊ Transparency Machine ◊ VMWare ESX Builder Misc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retrieve SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose Array Projects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalc Cool Stuff: AutoItObject UDF ◊ Extract Icon From Proc ◊ GuiCtrlFontRotate ◊ Hex Edit Funcs ◊ Run binary ◊ Service_UDF
AlchemistZim Posted December 13, 2022 Posted December 13, 2022 Quote Close, but notice that your logic only outputs when fizz, buzz, or fizzbuzz are present. Ohh...I know I designed it that way, just as a proof of concept for my self...Originally the first line in the loop was $String = "$i - " so that it output every number 3 minutes later i came up with this Spoiler For $i = 1 to 101 $String = "" If Mod($i, 3) = 0 Then $String = $String & "Fizz" If Mod($i, 5) = 0 Then $String = $String & "Buzz" If $String = "" Then $String = $i ConsoleWrite(@CRLF & $String) Next I was just goofin and got bored one night Great work though
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now