Skip to content

Instantly share code, notes, and snippets.

@D-Nice
Created June 17, 2020 22:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save D-Nice/59c63c28cc838cf48cf1d7d1a81e78b4 to your computer and use it in GitHub Desktop.
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
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