aboutsummaryrefslogtreecommitdiff
path: root/challenge-143
diff options
context:
space:
mode:
authorMohammad S Anwar <mohammad.anwar@yahoo.com>2021-12-19 09:52:00 +0000
committerMohammad S Anwar <mohammad.anwar@yahoo.com>2021-12-19 09:52:00 +0000
commitad56dfbda0a72d99fc7a44a6c5de468a31a86ec3 (patch)
treea4b20d0ffb899f6a7345c9ae5ea039e0cc7f91b7 /challenge-143
parentc08b58f94cd8f4fcbe3c151e8a4b35a957b4df55 (diff)
downloadperlweeklychallenge-club-ad56dfbda0a72d99fc7a44a6c5de468a31a86ec3.tar.gz
perlweeklychallenge-club-ad56dfbda0a72d99fc7a44a6c5de468a31a86ec3.tar.bz2
perlweeklychallenge-club-ad56dfbda0a72d99fc7a44a6c5de468a31a86ec3.zip
- Added solution by Mark Senn.
Diffstat (limited to 'challenge-143')
-rw-r--r--challenge-143/mark-senn/blog.txt1
-rw-r--r--challenge-143/mark-senn/raku/ch-2.raku16
-rw-r--r--challenge-143/mark-senn/wolfram/ch-2.wl7
3 files changed, 24 insertions, 0 deletions
diff --git a/challenge-143/mark-senn/blog.txt b/challenge-143/mark-senn/blog.txt
new file mode 100644
index 0000000000..4d4d1b83b8
--- /dev/null
+++ b/challenge-143/mark-senn/blog.txt
@@ -0,0 +1 @@
+https://engineering.purdue.edu/~mark/twc-143-2.pdf
diff --git a/challenge-143/mark-senn/raku/ch-2.raku b/challenge-143/mark-senn/raku/ch-2.raku
new file mode 100644
index 0000000000..f0ebadf637
--- /dev/null
+++ b/challenge-143/mark-senn/raku/ch-2.raku
@@ -0,0 +1,16 @@
+use v6;
+
+# Read $n.
+my $n = $*IN.get;
+
+# Get divisors of $n from 1 to sqrt($n). If $n is 36 then @d1 is (1, 2, 3, 4, 6).
+my @d1 = (1 .. sqrt $n).grep({ $n %% $_ });
+
+# Get divisors of $n from $n down to sqrt($n). If $n is 36 then @d2 is (36, 18, 12, 9, 6).
+my @d2 = $n <</<< @d1;
+
+# Add divisors in @d1 and @d2 together. If $n is 36 then @sum is (37, 20, 15, 13, 12).
+my @sum = @d1 <<+>> @d2;
+
+# If there are any @sum entries that differ by one print "1", otherwise print "0".
+say (@sum.any == @sum.any+1) ?? 1 !! 0;
diff --git a/challenge-143/mark-senn/wolfram/ch-2.wl b/challenge-143/mark-senn/wolfram/ch-2.wl
new file mode 100644
index 0000000000..5b5c4195d9
--- /dev/null
+++ b/challenge-143/mark-senn/wolfram/ch-2.wl
@@ -0,0 +1,7 @@
+n = Input[];
+solution = Solve[
+ a > 0 && b > 0 && c > 0 && d > 0 && a b = c d && c d == n && a + b = c + d + 1,
+ {a, b, c, d},
+ Integers
+];
+If [solution == {}, Print[0], Print[1]];