Created
June 17, 2020 22:56
-
-
Save D-Nice/59c63c28cc838cf48cf1d7d1a81e78b4 to your computer and use it in GitHub Desktop.
Showcase of my take on fizzbuzz for a friend that is learning some programming languages. Try at https://play.nim-lang.org/#ix=2prQ
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sequtils, tables, strutils | |
const gameRange = (1..100).toSeq | |
const gameRuleTable = { | |
3: "Fizz", | |
5: "Buzz" | |
}.toOrderedTable | |
proc gameRules(x: int): string = | |
for k,v in gameRuleTable.pairs: | |
if x mod k == 0: | |
result.add v | |
if result.len == 0: | |
result = $x | |
const fizzBuzz = gameRange.map gameRules | |
const gameOutput = fizzBuzz.join("\p") | |
echo gameOutput |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment