aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-147/abigail/awk/ch-1.awk52
-rw-r--r--challenge-147/abigail/awk/ch-2.awk26
2 files changed, 78 insertions, 0 deletions
diff --git a/challenge-147/abigail/awk/ch-1.awk b/challenge-147/abigail/awk/ch-1.awk
new file mode 100644
index 0000000000..c39dc35247
--- /dev/null
+++ b/challenge-147/abigail/awk/ch-1.awk
@@ -0,0 +1,52 @@
+#!/usr/bin/awk
+
+#
+# See https://theweeklychallenge.org/blog/perl-weekly-challenge-147
+#
+
+#
+# Run as: awk -f ch-1.awk
+#
+
+func is_prime (n, i) {
+ if (n % 2 == 0) {return 0}
+ for (i = 3; i <= sqrt (n); i += 2) {
+ if (n % i == 0) {
+ return 0
+ }
+ }
+ return 1
+}
+
+BEGIN {
+ todo [1] = 2
+ todo [2] = 3
+ todo [3] = 5
+ todo [4] = 7
+ n = 4
+ i = 1
+ count = 20 - n;
+
+ printf ("2 3 5 7 ")
+
+ low = 1
+ high = n
+ while (count > 0) {
+ for (d = 1; d <= 9 && count > 0; d ++) {
+ for (i = low; i <= high && count > 0; i ++) {
+ candidate = d todo [i]
+ if (is_prime(candidate) == 1) {
+ printf candidate " "
+ count --;
+ todo [++ n] = candidate;
+ }
+ }
+ }
+ low = high + 1
+ high = n
+ }
+ printf ("\n")
+}
+
+
+
diff --git a/challenge-147/abigail/awk/ch-2.awk b/challenge-147/abigail/awk/ch-2.awk
new file mode 100644
index 0000000000..e071da78fc
--- /dev/null
+++ b/challenge-147/abigail/awk/ch-2.awk
@@ -0,0 +1,26 @@
+#!/usr/bin/awk
+
+#
+# See https://theweeklychallenge.org/blog/perl-weekly-challenge-147
+#
+
+#
+# Run as: awk -f ch-2.awk
+#
+
+BEGIN {
+ while (!done) {
+ p += n + n + n ++ + 1
+ pentagon [p] = 1
+
+ for (seen in pentagon) {
+ if (seen + seen < p && (p - seen) in pentagon \
+ && (p - seen - seen) in pentagon ) {
+ print seen, p - seen
+ done = 1
+ break
+ }
+ }
+ }
+}
+