From 5eacc0630711a4acd1305409c899a6a06c323ada Mon Sep 17 00:00:00 2001 From: Thibaud Date: Mon, 28 Jul 2025 17:06:17 +0200 Subject: [PATCH] 2018 day5 --- 2018/day5/day5.py | 25 +++++++++++++++++++++++++ 2018/day6/day6.py | 13 +++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 2018/day5/day5.py create mode 100644 2018/day6/day6.py diff --git a/2018/day5/day5.py b/2018/day5/day5.py new file mode 100644 index 0000000..1bfb5f0 --- /dev/null +++ b/2018/day5/day5.py @@ -0,0 +1,25 @@ +def reduce_polymer(p): + res = [""] + for x in p: + if res[-1].swapcase() == x: + res.pop() + else: + res.append(x) + return "".join(res) + + +def main(inp): + print("Part 1: ", len(reduce_polymer(inp))) + letters = set(x.lower() for x in inp) + min_ = 2 << 32 + for l in letters: + p = inp.replace(l.lower(), "").replace(l.upper(), "") + min_ = min(len(reduce_polymer(p)), min_) + print("Part 2: ", min_) + + +if __name__ == "__main__": + import fileinput + inp = next(l.rstrip() for l in fileinput.input()) + main(inp) + diff --git a/2018/day6/day6.py b/2018/day6/day6.py new file mode 100644 index 0000000..d7c594b --- /dev/null +++ b/2018/day6/day6.py @@ -0,0 +1,13 @@ +def dist(a, b): + "manhattan distance" + return abs(a.x - b.x) + abs(a.y - b.y) + +def main(inp): + pass + + +if __name__ == "__main__": + import fileinput + inp = list(l.rstrip() for l in fileinput.input()) + main(inp) +