diff options
| author | Archargelod <archargelod@gmail.com> | 2024-03-08 19:02:07 +0800 |
|---|---|---|
| committer | Archargelod <archargelod@gmail.com> | 2024-03-08 19:02:07 +0800 |
| commit | c45f2d8a7ae3836921747c832d2bfe9db7cc9aa9 (patch) | |
| tree | cea6fb0f51440f00210ab68d018e334c92bc7ef5 /challenge-033/archargelod | |
| parent | 510484bb98b0d2413f8c09c0a827e91b992d2533 (diff) | |
| download | perlweeklychallenge-club-c45f2d8a7ae3836921747c832d2bfe9db7cc9aa9.tar.gz perlweeklychallenge-club-c45f2d8a7ae3836921747c832d2bfe9db7cc9aa9.tar.bz2 perlweeklychallenge-club-c45f2d8a7ae3836921747c832d2bfe9db7cc9aa9.zip | |
weeks 27-40, 259 in Nim
Diffstat (limited to 'challenge-033/archargelod')
| -rw-r--r-- | challenge-033/archargelod/README | 1 | ||||
| -rwxr-xr-x | challenge-033/archargelod/nim/ch_1.nim | 20 | ||||
| -rwxr-xr-x | challenge-033/archargelod/nim/ch_2.nim | 22 |
3 files changed, 43 insertions, 0 deletions
diff --git a/challenge-033/archargelod/README b/challenge-033/archargelod/README new file mode 100644 index 0000000000..6cd57e1074 --- /dev/null +++ b/challenge-033/archargelod/README @@ -0,0 +1 @@ +Solution by archargelod diff --git a/challenge-033/archargelod/nim/ch_1.nim b/challenge-033/archargelod/nim/ch_1.nim new file mode 100755 index 0000000000..211e001742 --- /dev/null +++ b/challenge-033/archargelod/nim/ch_1.nim @@ -0,0 +1,20 @@ +#!/usr/bin/env -S nim r -d:release --verbosity:0 --hints:off +import std/[strutils, tables, streams] + +proc countLetters(filename: string): CountTable[char] = + let f = newFileStream(filename) + defer: + f.close() + while not f.atEnd(): + let c = f.readChar() + if c in Letters: + result.inc(c) + +proc main = + var counts = countLetters("/usr/share/dict/words") + counts.sort() + for c, cnt in counts: + echo c, ": ", cnt + +when isMainModule: + main() diff --git a/challenge-033/archargelod/nim/ch_2.nim b/challenge-033/archargelod/nim/ch_2.nim new file mode 100755 index 0000000000..f93e0e00d3 --- /dev/null +++ b/challenge-033/archargelod/nim/ch_2.nim @@ -0,0 +1,22 @@ +#!/usr/bin/env -S nim r -d:release --verbosity:0 --hints:off +import std/[strutils, strformat] + +proc printMultiplicationTable(max: Positive) = + # header + stdout.write " x|" + for i in 1..max: stdout.write &"{i:4}" + stdout.write '\n' + echo "---+", '-'.repeat(max*4) + # body + for i in 1..max: + stdout.write &"{i:3}|" + for j in 1..max: + if j < i: + stdout.write ' '.repeat(4) + else: + stdout.write &"{i*j:4}" + + stdout.write '\n' + +when isMainModule: + printMultiplicationTable(11) |
