aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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