aboutsummaryrefslogtreecommitdiff
path: root/challenge-151/sgreen/python/ch-2.py
diff options
context:
space:
mode:
authorSimon Green <mail@simon.green>2022-02-13 17:56:21 +1100
committerSimon Green <mail@simon.green>2022-02-13 17:56:21 +1100
commit93424d2f86a103e895912599f00b2e4049555708 (patch)
treedf5653eca3d101bd0b2d1303b0be9cbe2b9a0747 /challenge-151/sgreen/python/ch-2.py
parentd4fec6b7157921fd3a1f1178f0899696c4d405d5 (diff)
downloadperlweeklychallenge-club-93424d2f86a103e895912599f00b2e4049555708.tar.gz
perlweeklychallenge-club-93424d2f86a103e895912599f00b2e4049555708.tar.bz2
perlweeklychallenge-club-93424d2f86a103e895912599f00b2e4049555708.zip
sgreen solutions to challenge 151
Diffstat (limited to 'challenge-151/sgreen/python/ch-2.py')
-rwxr-xr-xchallenge-151/sgreen/python/ch-2.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/challenge-151/sgreen/python/ch-2.py b/challenge-151/sgreen/python/ch-2.py
new file mode 100755
index 0000000000..094f071037
--- /dev/null
+++ b/challenge-151/sgreen/python/ch-2.py
@@ -0,0 +1,28 @@
+#!/usr/bin/env python3
+
+import sys
+
+
+def rob(haul, valuables):
+ if len(valuables) <= 2:
+ # We rob the remaining house, and take off with the haul!
+ return haul + valuables[0]
+
+ # Call the function recursively skipping either one or two houses
+ hauls = []
+ hauls.append(rob(haul+valuables[0], valuables[2:]))
+ if len(valuables) >= 4:
+ hauls.append(rob(haul+valuables[0], valuables[3:]))
+
+ # Return the largest haul
+ return max(hauls)
+
+
+def main(inputs):
+ valuables = list(map(int, inputs))
+ largest_haul = rob(0, valuables)
+ print(largest_haul)
+
+
+if __name__ == '__main__':
+ main(sys.argv[1:])