diff options
| author | Abigail <abigail@abigail.freedom.nl> | 2021-12-13 13:22:04 +0100 |
|---|---|---|
| committer | Abigail <abigail@abigail.freedom.nl> | 2021-12-13 13:35:10 +0100 |
| commit | a9419595b246ec2ba94db259326024b980513dc3 (patch) | |
| tree | 2401f5fc3482c26dd0a6d19b996f01e9aae51a02 | |
| parent | 1458a9d1cc0a821b2e56b7b757a183a9b37ec1a8 (diff) | |
| download | perlweeklychallenge-club-a9419595b246ec2ba94db259326024b980513dc3.tar.gz perlweeklychallenge-club-a9419595b246ec2ba94db259326024b980513dc3.tar.bz2 perlweeklychallenge-club-a9419595b246ec2ba94db259326024b980513dc3.zip | |
Perl solutions for a boring week 143.
| -rw-r--r-- | challenge-143/abigail/README.md | 4 | ||||
| -rw-r--r-- | challenge-143/abigail/perl/ch-1.pl | 1 | ||||
| -rw-r--r-- | challenge-143/abigail/perl/ch-2.pl | 33 | ||||
| -rw-r--r-- | challenge-143/abigail/t/ctest.ini | 8 | ||||
| -rw-r--r-- | challenge-143/abigail/t/input-1-1 | 2 | ||||
| -rw-r--r-- | challenge-143/abigail/t/input-2-1 | 3 | ||||
| -rw-r--r-- | challenge-143/abigail/t/output-1-1.exp | 2 | ||||
| -rw-r--r-- | challenge-143/abigail/t/output-2-1.exp | 3 |
8 files changed, 56 insertions, 0 deletions
diff --git a/challenge-143/abigail/README.md b/challenge-143/abigail/README.md index d589af7261..aa835b7f1e 100644 --- a/challenge-143/abigail/README.md +++ b/challenge-143/abigail/README.md @@ -3,3 +3,7 @@ ## Part 1 * [Perl](perl/ch-1.pl) + +## Part 2 + +* [Perl](perl/ch-2.pl) diff --git a/challenge-143/abigail/perl/ch-1.pl b/challenge-143/abigail/perl/ch-1.pl new file mode 100644 index 0000000000..8ae1d21ccb --- /dev/null +++ b/challenge-143/abigail/perl/ch-1.pl @@ -0,0 +1 @@ +use 5.01;say eval for <> # Maybe a challenge for language without eval. Not Perl diff --git a/challenge-143/abigail/perl/ch-2.pl b/challenge-143/abigail/perl/ch-2.pl new file mode 100644 index 0000000000..2109647bf2 --- /dev/null +++ b/challenge-143/abigail/perl/ch-2.pl @@ -0,0 +1,33 @@ +#!/opt/perl/bin/perl + +use 5.032; + +use strict; +use warnings; +no warnings 'syntax'; + +use experimental 'signatures'; +use experimental 'lexical_subs'; + +# +# Run as: perl ch-2.pl < input-file +# + +# +# And for the fourth week in succession we're solving need the +# majority of the problem by getting the divisors of a number. +# +# Perhaps it is time to say: +# "I'm completely out of ideas, let's skip this week". +# +# Big Yawn +# + +use Math::Prime::Util qw [divisors]; + +while (my $n = <>) { + # Put sum of divisor pairs in hash. + my %s = map {$_ + $n / $_ => 1} divisors 0 + $n; + # Any difference of 1? + say grep ({$s {$_ - 1}} keys %s) ? 1 : 0; +} diff --git a/challenge-143/abigail/t/ctest.ini b/challenge-143/abigail/t/ctest.ini new file mode 100644 index 0000000000..575704342b --- /dev/null +++ b/challenge-143/abigail/t/ctest.ini @@ -0,0 +1,8 @@ +#
+# Configuration file for running tests, using ctest.
+# See https://github.com/Abigail/Misc/blob/master/ctest
+#
+
+[names]
+1-1 = Given Examples
+2-1 = Given Examples
diff --git a/challenge-143/abigail/t/input-1-1 b/challenge-143/abigail/t/input-1-1 new file mode 100644 index 0000000000..01dd3f8720 --- /dev/null +++ b/challenge-143/abigail/t/input-1-1 @@ -0,0 +1,2 @@ +10 + 20 - 5 +(10 + 20 - 5) * 2 diff --git a/challenge-143/abigail/t/input-2-1 b/challenge-143/abigail/t/input-2-1 new file mode 100644 index 0000000000..024f0e0086 --- /dev/null +++ b/challenge-143/abigail/t/input-2-1 @@ -0,0 +1,3 @@ +36 +12 +6 diff --git a/challenge-143/abigail/t/output-1-1.exp b/challenge-143/abigail/t/output-1-1.exp new file mode 100644 index 0000000000..e573c227f4 --- /dev/null +++ b/challenge-143/abigail/t/output-1-1.exp @@ -0,0 +1,2 @@ +25 +50 diff --git a/challenge-143/abigail/t/output-2-1.exp b/challenge-143/abigail/t/output-2-1.exp new file mode 100644 index 0000000000..2f1465d159 --- /dev/null +++ b/challenge-143/abigail/t/output-2-1.exp @@ -0,0 +1,3 @@ +1 +1 +0 |
