From 19e52cac4e51f4e2594e2fad666d16cb984f4d3b Mon Sep 17 00:00:00 2001 From: mfoda <23182653+mfoda@users.noreply.github.com> Date: Wed, 13 Jan 2021 15:08:18 +0800 Subject: Add mfoda-001-ch2-nim --- challenge-001/mfoda/nim/ch2.nim | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 challenge-001/mfoda/nim/ch2.nim diff --git a/challenge-001/mfoda/nim/ch2.nim b/challenge-001/mfoda/nim/ch2.nim new file mode 100644 index 0000000000..1b01317b3f --- /dev/null +++ b/challenge-001/mfoda/nim/ch2.nim @@ -0,0 +1,18 @@ +#[ + Write a one-liner to solve the FizzBuzz problem and print the numbers 1 through 20. + However, any number divisible by 3 should be replaced by the word ‘fizz’ and any divisible by 5 by the word ‘buzz’. + Those numbers that are both divisible by 3 and 5 become ‘fizzbuzz’. +]# + +import strutils + +var result: seq[string] +for i in 1..20: + let + div3 = i mod 3 == 0 + div5 = i mod 5 == 0 + if div3: result &= "fizz" + if div5: result &= "buzz" + if not div3 and not div5: result &= $i + +echo result.join \ No newline at end of file -- cgit