aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAbigail <abigail@abigail.be>2021-03-23 00:06:56 +0100
committerAbigail <abigail@abigail.be>2021-03-23 00:06:56 +0100
commit73778bb4438f496b569a60b06076b1a68ced45b4 (patch)
tree69988bb6c472f1b756ae955c527e58574dc00107
parent7ee8eee88d4037f3084a16e6d848f0078689c2e4 (diff)
downloadperlweeklychallenge-club-73778bb4438f496b569a60b06076b1a68ced45b4.tar.gz
perlweeklychallenge-club-73778bb4438f496b569a60b06076b1a68ced45b4.tar.bz2
perlweeklychallenge-club-73778bb4438f496b569a60b06076b1a68ced45b4.zip
bc solution for week 105, part 1
-rw-r--r--challenge-105/abigail/README.md1
-rw-r--r--challenge-105/abigail/bc/ch-1.bc34
-rw-r--r--challenge-105/abigail/t/ctest.ini4
3 files changed, 39 insertions, 0 deletions
diff --git a/challenge-105/abigail/README.md b/challenge-105/abigail/README.md
index 7a06241aae..f48953ce9f 100644
--- a/challenge-105/abigail/README.md
+++ b/challenge-105/abigail/README.md
@@ -18,6 +18,7 @@ Output: 2.02
### Solutions
* [AWK](awk/ch-1.awk)
+* [bc](bc/ch-1.bc)
* [C](c/ch-1.c)
* [Lua](lua/ch-1.lua)
* [Node.js](node/ch-1.js)
diff --git a/challenge-105/abigail/bc/ch-1.bc b/challenge-105/abigail/bc/ch-1.bc
new file mode 100644
index 0000000000..4a024c7056
--- /dev/null
+++ b/challenge-105/abigail/bc/ch-1.bc
@@ -0,0 +1,34 @@
+#
+# See ../README.md
+#
+
+#
+# Run as: bc -l ch-1.bc < input-file
+#
+# Input will consist of lines; each line will have two numbers, N and k, N > 0,
+# k > 0. For each line of input, we output a line with the Nth root of k.
+# The input file should end with a 0.
+#
+# We're not doing any input validations; we're assuming it's correct.
+#
+
+#
+# To find the Nth root of a number k, we calculate:
+#
+# ln (k)
+# ------
+# N
+# exp
+#
+# 1/N
+# which is equivalent to k
+#
+
+while (1) {
+ n = read ()
+ if (n == 0) {
+ break
+ }
+ k = read ()
+ e (l (k) / n)
+}
diff --git a/challenge-105/abigail/t/ctest.ini b/challenge-105/abigail/t/ctest.ini
index a85f6af6c9..dd26b3b198 100644
--- a/challenge-105/abigail/t/ctest.ini
+++ b/challenge-105/abigail/t/ctest.ini
@@ -12,3 +12,7 @@ precision = 6
[challenges/1/sql]
skip = "sqlite does not support POW"
+
+[challenges/1/bc]
+add_to_input = 0
+exe_args = -l %RUN_FILE