aboutsummaryrefslogtreecommitdiff
path: root/challenge-008/archargelod
diff options
context:
space:
mode:
authorSolathian <horvath6@gmail.com>2025-08-02 16:28:12 +0200
committerSolathian <horvath6@gmail.com>2025-08-02 16:28:12 +0200
commit4014f0eb1fa46f39fee72c2add76ca47f2dd1637 (patch)
tree07ed523115445f773f90f3d0f08c83456457e54e /challenge-008/archargelod
parent83179303806e75ac6aa4c786cefbb89ab6ddeaf7 (diff)
parent698c027e7ef73ac2753c97d4e64d7fba2b2ddc95 (diff)
downloadperlweeklychallenge-club-4014f0eb1fa46f39fee72c2add76ca47f2dd1637.tar.gz
perlweeklychallenge-club-4014f0eb1fa46f39fee72c2add76ca47f2dd1637.tar.bz2
perlweeklychallenge-club-4014f0eb1fa46f39fee72c2add76ca47f2dd1637.zip
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'challenge-008/archargelod')
-rw-r--r--challenge-008/archargelod/README1
-rwxr-xr-xchallenge-008/archargelod/nim/ch_1.nim13
-rwxr-xr-xchallenge-008/archargelod/nim/ch_2.nim23
3 files changed, 37 insertions, 0 deletions
diff --git a/challenge-008/archargelod/README b/challenge-008/archargelod/README
new file mode 100644
index 0000000000..6cd57e1074
--- /dev/null
+++ b/challenge-008/archargelod/README
@@ -0,0 +1 @@
+Solution by archargelod
diff --git a/challenge-008/archargelod/nim/ch_1.nim b/challenge-008/archargelod/nim/ch_1.nim
new file mode 100755
index 0000000000..2dd3eccd25
--- /dev/null
+++ b/challenge-008/archargelod/nim/ch_1.nim
@@ -0,0 +1,13 @@
+#!/usr/bin/env -S nim r -d:release --verbosity:0 --hints:off
+import std/math
+
+proc fivePerfectNumbers(): array[5, int] =
+ const Primes = [2, 3, 5, 7, 13]
+ for i, p in Primes:
+ result[i] = (2 ^ (p - 1)) * (2 ^ p - 1)
+
+when isMainModule:
+ import std/unittest
+ suite "Perfect numbers":
+ test "first 5 perfect numbers":
+ check fivePerfectNumbers() == [6, 28, 496, 8128, 33550336]
diff --git a/challenge-008/archargelod/nim/ch_2.nim b/challenge-008/archargelod/nim/ch_2.nim
new file mode 100755
index 0000000000..d96b378446
--- /dev/null
+++ b/challenge-008/archargelod/nim/ch_2.nim
@@ -0,0 +1,23 @@
+#!/usr/bin/env -S nim r -d:release --verbosity:0 --hints:off
+import std/strutils
+
+proc center(lines: varargs[string]): seq[string] =
+ let maxOffset = block:
+ var maxLen = 0
+ for line in lines:
+ if line.len > maxLen:
+ maxLen = line.len
+ maxLen div 2
+
+ for line in lines:
+ result.add ' '.repeat(maxOffset - line.len div 2) & line
+
+when isMainModule:
+ import std/unittest
+
+ const Example = ["This", "is", "a test of the", "center function"]
+ const Expected = [" This", " is", " a test of the", "center function"]
+
+ suite "Centering strings":
+ test "Example 1":
+ check center(Example) == Expected