aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-217/sgreen/README.md3
-rw-r--r--challenge-218/sgreen/README.md4
-rw-r--r--challenge-218/sgreen/blog.txt1
-rwxr-xr-xchallenge-218/sgreen/perl/ch-1.pl17
-rwxr-xr-xchallenge-218/sgreen/perl/ch-2.pl31
-rwxr-xr-xchallenge-218/sgreen/python/ch-1.py16
-rwxr-xr-xchallenge-218/sgreen/python/ch-2.py26
7 files changed, 93 insertions, 5 deletions
diff --git a/challenge-217/sgreen/README.md b/challenge-217/sgreen/README.md
deleted file mode 100644
index 1dceb6430a..0000000000
--- a/challenge-217/sgreen/README.md
+++ /dev/null
@@ -1,3 +0,0 @@
-# The Weekly Challenge 216
-
-Blog: [Letter frequency](https://dev.to/simongreennet/letter-frequency-338m)
diff --git a/challenge-218/sgreen/README.md b/challenge-218/sgreen/README.md
index 1dceb6430a..393dc9b36a 100644
--- a/challenge-218/sgreen/README.md
+++ b/challenge-218/sgreen/README.md
@@ -1,3 +1,3 @@
-# The Weekly Challenge 216
+# The Weekly Challenge 218
-Blog: [Letter frequency](https://dev.to/simongreennet/letter-frequency-338m)
+Blog: [The one about maximums](https://dev.to/simongreennet/the-one-about-maximums-40cm)
diff --git a/challenge-218/sgreen/blog.txt b/challenge-218/sgreen/blog.txt
new file mode 100644
index 0000000000..14f46c3e78
--- /dev/null
+++ b/challenge-218/sgreen/blog.txt
@@ -0,0 +1 @@
+https://dev.to/simongreennet/the-one-about-maximums-40cm \ No newline at end of file
diff --git a/challenge-218/sgreen/perl/ch-1.pl b/challenge-218/sgreen/perl/ch-1.pl
new file mode 100755
index 0000000000..3139fff84f
--- /dev/null
+++ b/challenge-218/sgreen/perl/ch-1.pl
@@ -0,0 +1,17 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+use feature 'say';
+use experimental 'signatures';
+
+use List::Util 'max';
+
+sub main (@array) {
+ @array = sort { $a <=> $b } @array;
+ my $solution1 = $array[-3] * $array[-2] * $array[-1];
+ my $solution2 = $array[0] * $array[1] * $array[-1];
+ say max( $solution1, $solution2 );
+}
+
+main(@ARGV); \ No newline at end of file
diff --git a/challenge-218/sgreen/perl/ch-2.pl b/challenge-218/sgreen/perl/ch-2.pl
new file mode 100755
index 0000000000..221d712e13
--- /dev/null
+++ b/challenge-218/sgreen/perl/ch-2.pl
@@ -0,0 +1,31 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+use integer;
+use feature 'say';
+use experimental 'signatures';
+
+use JSON 'decode_json';
+use List::Util qw(max sum);
+
+sub main ($matrix) {
+ my $solution = 0;
+ my $cols = scalar( @{ $matrix->[0] } );
+ my $xor_row = 2**$cols - 1;
+
+ # Convert the matrix into a row of integers
+ my @matrix = map { oct( '0b' . join( '', @$_ ) ) } @$matrix;
+
+ foreach my $col_xor ( 0 .. $xor_row ) {
+ my @xor_matrix = map { $_ ^ $col_xor } @matrix;
+ my $total = sum( map { max( $xor_row - $_, $_ ) } @xor_matrix );
+ if ( $total > $solution ) {
+ $solution = $total;
+ }
+ }
+
+ say $solution;
+}
+
+main( decode_json( $ARGV[0] ) ); \ No newline at end of file
diff --git a/challenge-218/sgreen/python/ch-1.py b/challenge-218/sgreen/python/ch-1.py
new file mode 100755
index 0000000000..7085e998f4
--- /dev/null
+++ b/challenge-218/sgreen/python/ch-1.py
@@ -0,0 +1,16 @@
+#!/usr/bin/env python
+
+import sys
+
+
+def main(array):
+ array = sorted(array)
+ solution1 = array[-3] * array[-2] * array[-1]
+ solution2 = array[0] * array[1] * array[-1]
+ print(max(solution1, solution2))
+
+
+if __name__ == '__main__':
+ # Turn the strings into integers
+ n = [int(i) for i in sys.argv[1:]]
+ main(n)
diff --git a/challenge-218/sgreen/python/ch-2.py b/challenge-218/sgreen/python/ch-2.py
new file mode 100755
index 0000000000..9ac2a65a8c
--- /dev/null
+++ b/challenge-218/sgreen/python/ch-2.py
@@ -0,0 +1,26 @@
+#!/usr/bin/env python3
+
+import json
+import sys
+from operator import xor
+
+
+def main(matrix):
+ solution = 0
+ cols = len(matrix[0])
+ xor_row = 2 ** cols - 1
+
+ # Convert the matrix into a row of integers
+ matrix = [int(''.join(str(b) for b in x), 2) for x in matrix]
+
+ for col_xor in range(2 ** cols):
+ xor_matrix = [xor(x, col_xor) for x in matrix]
+ total = sum([max(xor_row - x, x) for x in xor_matrix])
+ if total > solution:
+ solution = total
+
+ print(solution)
+
+
+if __name__ == '__main__':
+ main(json.loads(sys.argv[1]))