aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-136/abigail/README.md2
-rw-r--r--challenge-136/abigail/bc/ch-1.bc30
-rw-r--r--challenge-136/abigail/bc/ch-2.bc21
-rw-r--r--challenge-136/abigail/t/ctest.ini3
4 files changed, 56 insertions, 0 deletions
diff --git a/challenge-136/abigail/README.md b/challenge-136/abigail/README.md
index c990c62f96..ecd34dfa17 100644
--- a/challenge-136/abigail/README.md
+++ b/challenge-136/abigail/README.md
@@ -4,6 +4,7 @@
* [GNU AWK](awk/ch-1.gawk)
* [Bash](bash/ch-1.sh)
+* [Bc](bc/ch-1.bc)
* [C](c/ch-1.c)
* [Go](go/ch-1.go)
* [Lua](lua/ch-1.lua)
@@ -17,6 +18,7 @@
## Part 2
* [AWK](awk/ch-2.awk)
+* [Bc](bc/ch-2.bc)
* [C](c/ch-2.c)
* [Go](go/ch-2.go)
* [Lua](lua/ch-2.lua)
diff --git a/challenge-136/abigail/bc/ch-1.bc b/challenge-136/abigail/bc/ch-1.bc
new file mode 100644
index 0000000000..8f9f92486b
--- /dev/null
+++ b/challenge-136/abigail/bc/ch-1.bc
@@ -0,0 +1,30 @@
+#
+# See ../README.md
+#
+
+#
+# Run as: bc ch-1.bc < input-file
+#
+# Terminate input with a 0
+#
+
+define g (a, b) {
+ if (b > a) {return g (b, a)}
+ if (b > 0) {return g (b, a % b)}
+ return a
+}
+
+define p (n) {
+ if (n < 1) {return 0}
+ while (n % 2 == 0) n = n / 2
+ return n == 1
+}
+
+while (1) {
+ n = read (); if (n == 0) {break}
+ m = read (); if (m == 0) {break}
+ r = g (n, m)
+ r > 1 && p (r)
+}
+
+quit
diff --git a/challenge-136/abigail/bc/ch-2.bc b/challenge-136/abigail/bc/ch-2.bc
new file mode 100644
index 0000000000..060a779f3c
--- /dev/null
+++ b/challenge-136/abigail/bc/ch-2.bc
@@ -0,0 +1,21 @@
+#
+# See ../README.md
+#
+
+#
+# Run as: bc ch-2.bc < input-file
+#
+
+define d (t, f, p) {
+ if (t < f) {return 0}
+ if (t == f) {return 1}
+ return d (t - f, f + p, f) + d (t, f + p, f)
+}
+define c (t) {
+ return d (t, 1, 1)
+}
+
+while (1) {
+ n = read (); if (n == 0) {break}
+ c (n)
+}
diff --git a/challenge-136/abigail/t/ctest.ini b/challenge-136/abigail/t/ctest.ini
index 527781acbb..faa58e9882 100644
--- a/challenge-136/abigail/t/ctest.ini
+++ b/challenge-136/abigail/t/ctest.ini
@@ -6,3 +6,6 @@
[names]
1-1 = Given Examples
2-1 = Given Examples
+
+[languages/bc]
+add_to_input = 0