aboutsummaryrefslogtreecommitdiffstats
path: root/src/05/solve.py
diff options
context:
space:
mode:
authorLouis Burda <quent.burda@gmail.com>2023-04-07 17:18:18 -0400
committerLouis Burda <quent.burda@gmail.com>2023-04-07 17:19:39 -0400
commit87ab487d59fa85dbe2afa55cc841b02805ae42ca (patch)
treecd90ab715e1b5b5803674045dbafd6d51d27ac90 /src/05/solve.py
parent1bcc82c5bfbde87edd03c01ffdf9ee5934681592 (diff)
downloadaoc2018-python-87ab487d59fa85dbe2afa55cc841b02805ae42ca.tar.gz
aoc2018-python-87ab487d59fa85dbe2afa55cc841b02805ae42ca.zip
Reorder days into src
Diffstat (limited to 'src/05/solve.py')
-rw-r--r--src/05/solve.py30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/05/solve.py b/src/05/solve.py
new file mode 100644
index 0000000..263f9fd
--- /dev/null
+++ b/src/05/solve.py
@@ -0,0 +1,30 @@
+import sys
+sys.path.append("../common")
+import aoc
+
+data = aoc.data
+
+def react(s):
+ i = 0
+ while i < len(s)-1:
+ cs = "".join(s[i:i+2])
+ csl = cs.lower()
+ if csl[0] == csl[1] and cs[0] != cs[1]:
+ s.pop(i)
+ s.pop(i)
+ if i > 0:
+ i -= 1
+ else:
+ i += 1
+
+ return len(s)
+
+def solve1(args):
+ return react(list(data))
+
+def solve2(args):
+ react_wo = lambda x : react(list(data.replace(x, "").replace(x.upper(), "")))
+ alph = "abcdefghijklmnopqrstuvwxyz"
+ return min((react_wo(c) for c in alph))
+
+aoc.run(solve1, solve2, sols=[11364, 4212])