diff options
| author | Solathian <horvath6@gmail.com> | 2025-08-02 16:28:12 +0200 |
|---|---|---|
| committer | Solathian <horvath6@gmail.com> | 2025-08-02 16:28:12 +0200 |
| commit | 4014f0eb1fa46f39fee72c2add76ca47f2dd1637 (patch) | |
| tree | 07ed523115445f773f90f3d0f08c83456457e54e /challenge-008/archargelod | |
| parent | 83179303806e75ac6aa4c786cefbb89ab6ddeaf7 (diff) | |
| parent | 698c027e7ef73ac2753c97d4e64d7fba2b2ddc95 (diff) | |
| download | perlweeklychallenge-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/README | 1 | ||||
| -rwxr-xr-x | challenge-008/archargelod/nim/ch_1.nim | 13 | ||||
| -rwxr-xr-x | challenge-008/archargelod/nim/ch_2.nim | 23 |
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 |
