aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAbigail <abigail@abigail.be>2021-01-13 01:01:42 +0100
committerAbigail <abigail@abigail.be>2021-01-13 01:01:42 +0100
commita3dea75d72159867d20a129371c5db803c5b3859 (patch)
treece9650d7a2eb16ef79caafc4d0597d2d56239e6d
parent0c8f6ef93b4400b4574089c085d79d413c94532d (diff)
downloadperlweeklychallenge-club-a3dea75d72159867d20a129371c5db803c5b3859.tar.gz
perlweeklychallenge-club-a3dea75d72159867d20a129371c5db803c5b3859.tar.bz2
perlweeklychallenge-club-a3dea75d72159867d20a129371c5db803c5b3859.zip
Perl solution for week 76/part 1
-rw-r--r--challenge-076/abigail/README1
-rw-r--r--challenge-076/abigail/README.md21
-rw-r--r--challenge-076/abigail/perl/ch-1.pl33
-rw-r--r--challenge-076/abigail/t/ctest.ini4
-rw-r--r--challenge-076/abigail/t/input-1-11
-rw-r--r--challenge-076/abigail/t/input-1-29
-rw-r--r--challenge-076/abigail/t/input-1-38
-rw-r--r--challenge-076/abigail/t/output-1-1.exp1
-rw-r--r--challenge-076/abigail/t/output-1-2.exp9
-rw-r--r--challenge-076/abigail/t/output-1-3.exp8
10 files changed, 94 insertions, 1 deletions
diff --git a/challenge-076/abigail/README b/challenge-076/abigail/README
deleted file mode 100644
index 5f0d73ae16..0000000000
--- a/challenge-076/abigail/README
+++ /dev/null
@@ -1 +0,0 @@
-Solution by Abigail
diff --git a/challenge-076/abigail/README.md b/challenge-076/abigail/README.md
new file mode 100644
index 0000000000..d40e979e24
--- /dev/null
+++ b/challenge-076/abigail/README.md
@@ -0,0 +1,21 @@
+# Solution by Abigail
+
+## [Prime Sum](https://perlweeklychallenge.org/blog/perl-weekly-challenge-076/#TASK1)
+
+You are given a number `$N`. Write a script to find the minimum number
+of prime numbers required, whose summation gives you `$N`.
+
+For the sake of this task, please assume `1` is not a prime number.
+
+### Example
+~~~~
+Input:
+ $N = 9
+
+Ouput:
+ 2 as sum of 2 prime numbers i.e. 2 and 7 is same as the input number.
+ 2 + 7 = 9.
+~~~~
+
+### Solutions
+* [Perl](perl/ch-1.c)
diff --git a/challenge-076/abigail/perl/ch-1.pl b/challenge-076/abigail/perl/ch-1.pl
new file mode 100644
index 0000000000..973607ada4
--- /dev/null
+++ b/challenge-076/abigail/perl/ch-1.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';
+
+use Math::Prime::Util qw [is_prime];
+
+#
+# The Goldbach conjecture says that every even number greater than 2
+# is the sum of two primes. This has been verified for numbers up to
+# 4 * 10^18. We will assume it's always true.
+#
+# This means the answer is:
+#
+# No answer, if the number is less than 2;
+# 1, if the number is prime;
+# 2, if the number is even, or 2 more than a prime number;
+# 3, otherwise.
+#
+
+while (<>) {
+ chomp;
+ say $_ < 2 ? "No answer possible"
+ : is_prime ($_) ? 1
+ : ($_ % 2 == 0) || is_prime ($_ - 2) ? 2
+ : 3;
+}
diff --git a/challenge-076/abigail/t/ctest.ini b/challenge-076/abigail/t/ctest.ini
new file mode 100644
index 0000000000..c926397ef7
--- /dev/null
+++ b/challenge-076/abigail/t/ctest.ini
@@ -0,0 +1,4 @@
+[names]
+1-1 = Given example
+1-2 = Some 2 digit cases
+1-3 = Some 12 digit cases
diff --git a/challenge-076/abigail/t/input-1-1 b/challenge-076/abigail/t/input-1-1
new file mode 100644
index 0000000000..ec635144f6
--- /dev/null
+++ b/challenge-076/abigail/t/input-1-1
@@ -0,0 +1 @@
+9
diff --git a/challenge-076/abigail/t/input-1-2 b/challenge-076/abigail/t/input-1-2
new file mode 100644
index 0000000000..f2cc29bfff
--- /dev/null
+++ b/challenge-076/abigail/t/input-1-2
@@ -0,0 +1,9 @@
+17
+19
+23
+45
+56
+88
+77
+95
+35
diff --git a/challenge-076/abigail/t/input-1-3 b/challenge-076/abigail/t/input-1-3
new file mode 100644
index 0000000000..23e7e0e43c
--- /dev/null
+++ b/challenge-076/abigail/t/input-1-3
@@ -0,0 +1,8 @@
+123456791467
+123456791468
+123456791469
+123456791471
+778899226751
+778899226752
+778899226753
+778899226755
diff --git a/challenge-076/abigail/t/output-1-1.exp b/challenge-076/abigail/t/output-1-1.exp
new file mode 100644
index 0000000000..0cfbf08886
--- /dev/null
+++ b/challenge-076/abigail/t/output-1-1.exp
@@ -0,0 +1 @@
+2
diff --git a/challenge-076/abigail/t/output-1-2.exp b/challenge-076/abigail/t/output-1-2.exp
new file mode 100644
index 0000000000..8ecb43a2ae
--- /dev/null
+++ b/challenge-076/abigail/t/output-1-2.exp
@@ -0,0 +1,9 @@
+1
+1
+1
+2
+2
+2
+3
+3
+3
diff --git a/challenge-076/abigail/t/output-1-3.exp b/challenge-076/abigail/t/output-1-3.exp
new file mode 100644
index 0000000000..b7cf8c43b2
--- /dev/null
+++ b/challenge-076/abigail/t/output-1-3.exp
@@ -0,0 +1,8 @@
+1
+2
+2
+3
+1
+2
+2
+3