aboutsummaryrefslogtreecommitdiff
path: root/challenge-011
diff options
context:
space:
mode:
authorArchargelod <archargelod@gmail.com>2024-02-21 01:33:32 +0800
committerArchargelod <archargelod@gmail.com>2024-02-21 01:33:32 +0800
commit77f7f91c73773aa6cfd2713dea32c705a1971b58 (patch)
tree368b987ea819a1083930390e2cef19151827c4d6 /challenge-011
parentddd42e0db3017a5ec3108d09efba477f19e7f04b (diff)
downloadperlweeklychallenge-club-77f7f91c73773aa6cfd2713dea32c705a1971b58.tar.gz
perlweeklychallenge-club-77f7f91c73773aa6cfd2713dea32c705a1971b58.tar.bz2
perlweeklychallenge-club-77f7f91c73773aa6cfd2713dea32c705a1971b58.zip
Weeks 5-13, 257 in Nim
Diffstat (limited to 'challenge-011')
-rw-r--r--challenge-011/archargelod/README1
-rwxr-xr-xchallenge-011/archargelod/nim/ch_1.nim24
-rwxr-xr-xchallenge-011/archargelod/nim/ch_2.nim25
3 files changed, 50 insertions, 0 deletions
diff --git a/challenge-011/archargelod/README b/challenge-011/archargelod/README
new file mode 100644
index 0000000000..6cd57e1074
--- /dev/null
+++ b/challenge-011/archargelod/README
@@ -0,0 +1 @@
+Solution by archargelod
diff --git a/challenge-011/archargelod/nim/ch_1.nim b/challenge-011/archargelod/nim/ch_1.nim
new file mode 100755
index 0000000000..b7514dd648
--- /dev/null
+++ b/challenge-011/archargelod/nim/ch_1.nim
@@ -0,0 +1,24 @@
+#!/usr/bin/env -S nim r -d:release --verbosity:0 --hints:off
+import std/math
+
+const
+ CelsiusFreezing = 0
+ CelsiusBoiling = 100
+ FahrenheitFreezing = 32
+ FahrenheitBoiling = 212
+
+proc toFahrenheit(t: int): int =
+ let slope =
+ (FahrenheitBoiling - FahrenheitFreezing) / (CelsiusBoiling - CelsiusFreezing)
+ int round(FahrenheitFreezing.float + slope * float(t - CelsiusFreezing))
+
+proc equalPoint(): int =
+ while result.toFahrenheit() > result:
+ dec result
+
+when isMainModule:
+ import std/unittest
+
+ suite "Equal point in Fahrenheit and Celsius":
+ test "-40 is the equal point":
+ check equalPoint() == -40
diff --git a/challenge-011/archargelod/nim/ch_2.nim b/challenge-011/archargelod/nim/ch_2.nim
new file mode 100755
index 0000000000..6865bd40f5
--- /dev/null
+++ b/challenge-011/archargelod/nim/ch_2.nim
@@ -0,0 +1,25 @@
+#!/usr/bin/env -S nim r -d:release --verbosity:0 --hints:off
+import std/[sequtils]
+
+type Matrix = seq[seq[int]]
+
+proc identityMatrix*(size: Positive): Matrix =
+ result = newSeqWith[int](size, newSeq[int](size))
+ for i in 0 ..< size:
+ result[i][i] = 1
+
+when isMainModule:
+ import std/unittest
+
+ suite "Identity matrix of given size":
+ test "2x2 matrix":
+ check identityMatrix(2) == [@[1, 0], @[0, 1]]
+ test "6x6 matrix":
+ check identityMatrix(6) == [
+ @[1, 0, 0, 0, 0, 0],
+ @[0, 1, 0, 0, 0, 0],
+ @[0, 0, 1, 0, 0, 0],
+ @[0, 0, 0, 1, 0, 0],
+ @[0, 0, 0, 0, 1, 0],
+ @[0, 0, 0, 0, 0, 1]
+ ]