aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2021-01-14 01:48:00 +0000
committerGitHub <noreply@github.com>2021-01-14 01:48:00 +0000
commit64c688637441ca8ef6a86fa7df5d51a8363f0af9 (patch)
tree50eb3af271048f99a17594bd0b4c0eecaba6963b
parente49b239721f9621482e42d7a88e837b90553570f (diff)
parent19e52cac4e51f4e2594e2fad666d16cb984f4d3b (diff)
downloadperlweeklychallenge-club-64c688637441ca8ef6a86fa7df5d51a8363f0af9.tar.gz
perlweeklychallenge-club-64c688637441ca8ef6a86fa7df5d51a8363f0af9.tar.bz2
perlweeklychallenge-club-64c688637441ca8ef6a86fa7df5d51a8363f0af9.zip
Merge pull request #3245 from mfoda/mfoda-002-nim
Add mfoda-001-ch2-nim
-rw-r--r--challenge-001/mfoda/nim/ch2.nim18
1 files changed, 18 insertions, 0 deletions
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