aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Green <mail@simon.green>2023-01-26 14:06:10 +1100
committerSimon Green <mail@simon.green>2023-01-26 14:06:10 +1100
commitc10e79f3ad4feb2137b3accb1fff4faf64812e75 (patch)
tree5776e42f46e16d077e841e47c9e6fa68d551b9bb
parent27b88f614b9bb53872ef0da19a56087505836db0 (diff)
downloadperlweeklychallenge-club-c10e79f3ad4feb2137b3accb1fff4faf64812e75.tar.gz
perlweeklychallenge-club-c10e79f3ad4feb2137b3accb1fff4faf64812e75.tar.bz2
perlweeklychallenge-club-c10e79f3ad4feb2137b3accb1fff4faf64812e75.zip
Simon's solution to challenge 201
-rw-r--r--challenge-201/sgreen/README.md4
-rw-r--r--challenge-201/sgreen/blog.txt1
-rwxr-xr-xchallenge-201/sgreen/perl/ch-1.pl18
-rwxr-xr-xchallenge-201/sgreen/perl/ch-2.pl27
-rwxr-xr-xchallenge-201/sgreen/python/ch-1.py15
-rwxr-xr-xchallenge-201/sgreen/python/ch-2.py24
6 files changed, 87 insertions, 2 deletions
diff --git a/challenge-201/sgreen/README.md b/challenge-201/sgreen/README.md
index bd88165103..e7306a3042 100644
--- a/challenge-201/sgreen/README.md
+++ b/challenge-201/sgreen/README.md
@@ -1,3 +1,3 @@
-# The Weekly Challenge 200
+# The Weekly Challenge 201
-Blog: [Two hundred slices](https://dev.to/simongreennet/two-hundred-slices-ach) \ No newline at end of file
+Blog: [Missing pennies](https://dev.to/simongreennet/missing-pennies-3791)
diff --git a/challenge-201/sgreen/blog.txt b/challenge-201/sgreen/blog.txt
new file mode 100644
index 0000000000..fc8c09b820
--- /dev/null
+++ b/challenge-201/sgreen/blog.txt
@@ -0,0 +1 @@
+https://dev.to/simongreennet/missing-pennies-3791 \ No newline at end of file
diff --git a/challenge-201/sgreen/perl/ch-1.pl b/challenge-201/sgreen/perl/ch-1.pl
new file mode 100755
index 0000000000..cae9180130
--- /dev/null
+++ b/challenge-201/sgreen/perl/ch-1.pl
@@ -0,0 +1,18 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+use feature 'say';
+use experimental 'signatures';
+
+sub main (@n) {
+ # Turn the array into a hash
+ my %n = map { $_, 1 } @n;
+
+ # Find numbers between 0 and the length of n that don't appear in the input
+ my @missing = grep { !exists( $n{$_} ) } ( 0 .. $#n + 1 );
+
+ say join ', ', @missing;
+}
+
+main(@ARGV); \ No newline at end of file
diff --git a/challenge-201/sgreen/perl/ch-2.pl b/challenge-201/sgreen/perl/ch-2.pl
new file mode 100755
index 0000000000..d7e917c425
--- /dev/null
+++ b/challenge-201/sgreen/perl/ch-2.pl
@@ -0,0 +1,27 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+use feature 'say';
+use experimental 'signatures';
+
+sub pile ( $remain, $minimum ) {
+ my $found = 0;
+ foreach my $take ( $minimum .. $remain ) {
+ if ( $remain == $take ) {
+ # We have a solution
+ $found++;
+ }
+ else: {
+ # Take this amount from the remaining pennies
+ $found += pile( $remain - $take, $take );
+ }
+ }
+ return $found;
+}
+
+sub main ($n) {
+ say pile( $n, 1 );
+}
+
+main( $ARGV[0] ); \ No newline at end of file
diff --git a/challenge-201/sgreen/python/ch-1.py b/challenge-201/sgreen/python/ch-1.py
new file mode 100755
index 0000000000..e42e28f11c
--- /dev/null
+++ b/challenge-201/sgreen/python/ch-1.py
@@ -0,0 +1,15 @@
+#!/usr/bin/env python3
+
+import sys
+
+
+def main(n):
+ # Find numbers between 0 and the length of n that don't appear in the input
+ missing = [i for i in range(len(n)+1) if i not in n]
+ print(*missing, sep=', ')
+
+
+if __name__ == '__main__':
+ # Turn the strings into integers
+ n = [int(i) for i in sys.argv[1:]]
+ main(n)
diff --git a/challenge-201/sgreen/python/ch-2.py b/challenge-201/sgreen/python/ch-2.py
new file mode 100755
index 0000000000..9899aa8557
--- /dev/null
+++ b/challenge-201/sgreen/python/ch-2.py
@@ -0,0 +1,24 @@
+#!/usr/bin/env python3
+
+import sys
+
+
+def pile(remain, minimum):
+ found = 0
+ for take in range(minimum, remain+1):
+ if remain == take:
+ # We have a solution
+ found += 1
+ else:
+ # Take this amount from the remaining pennies
+ found += pile(remain - take, take)
+
+ return found
+
+
+def main(n):
+ print(pile(n, 1))
+
+
+if __name__ == '__main__':
+ main(int(sys.argv[1]))