aboutsummaryrefslogtreecommitdiff
path: root/challenge-139/abigail/bc
diff options
context:
space:
mode:
authorAbigail <abigail@abigail.be>2021-11-17 16:09:09 +0100
committerAbigail <abigail@abigail.be>2021-11-17 19:20:28 +0100
commit62167a58d3c55a71f37815381c858fad45825a8d (patch)
treec2dab46599fc720673c6f1b4c8378c00e99dfeb2 /challenge-139/abigail/bc
parent83b91177f7b1aced78863b336bd236a40f7e1aef (diff)
downloadperlweeklychallenge-club-62167a58d3c55a71f37815381c858fad45825a8d.tar.gz
perlweeklychallenge-club-62167a58d3c55a71f37815381c858fad45825a8d.tar.bz2
perlweeklychallenge-club-62167a58d3c55a71f37815381c858fad45825a8d.zip
Solutions for week 139
Diffstat (limited to 'challenge-139/abigail/bc')
-rw-r--r--challenge-139/abigail/bc/ch-1.bc27
-rw-r--r--challenge-139/abigail/bc/ch-2.bc40
2 files changed, 67 insertions, 0 deletions
diff --git a/challenge-139/abigail/bc/ch-1.bc b/challenge-139/abigail/bc/ch-1.bc
new file mode 100644
index 0000000000..4afe2a1c11
--- /dev/null
+++ b/challenge-139/abigail/bc/ch-1.bc
@@ -0,0 +1,27 @@
+#
+# See ../README.md
+#
+
+#
+# Run as: bc ch-1.bc < input-file
+#
+# End each line with a 0.
+# End the input with a 0 as the first number on a line
+#
+
+
+while (1) {
+ prev = read(); if (prev == 0) break; # End of input
+ sorted = 1;
+ while (1) {
+ next = read()
+ if (next == 0) { # End of line
+ sorted
+ break
+ }
+ if (prev > next) {
+ sorted = 0
+ }
+ prev = next
+ }
+}
diff --git a/challenge-139/abigail/bc/ch-2.bc b/challenge-139/abigail/bc/ch-2.bc
new file mode 100644
index 0000000000..c51b1ab38d
--- /dev/null
+++ b/challenge-139/abigail/bc/ch-2.bc
@@ -0,0 +1,40 @@
+#
+# See ../README.md
+#
+
+#
+# Run as: bc ch-2.bc
+#
+
+base = 10
+count = 5
+
+define is_long (number) {
+ for (i = 0; i < number; i ++) {
+ seen [i] = 0
+ }
+ rest = 0
+ for (i = 2; i <= number; i ++) {
+ rest = (rest * base + base - 1) % number
+ if (seen [rest] > 0) {
+ return (0)
+ }
+ seen [rest] = 1
+ }
+ return (1)
+}
+
+
+number = 1
+for (;count > 0;) {
+ number = number + 1
+ if (base % number == 0) {
+ continue
+ }
+ if (is_long (number) == 1) {
+ number
+ count = count - 1
+ }
+}
+
+quit