aboutsummaryrefslogtreecommitdiff
path: root/challenge-218/sgreen/python
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-218/sgreen/python')
-rwxr-xr-xchallenge-218/sgreen/python/ch-1.py16
-rwxr-xr-xchallenge-218/sgreen/python/ch-2.py26
2 files changed, 42 insertions, 0 deletions
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]))