From f4741b6158a9bf656ec7e0ee7bc67249ab2f1294 Mon Sep 17 00:00:00 2001 From: Arthur Date: Mon, 4 Dec 2023 10:32:36 +0100 Subject: [PATCH] d04 part two --- d04/run2.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 d04/run2.py diff --git a/d04/run2.py b/d04/run2.py new file mode 100644 index 0000000..2e0df75 --- /dev/null +++ b/d04/run2.py @@ -0,0 +1,28 @@ +import sys +from functools import reduce + +def main(myList, S = 0): + card=[c.split(": ")[1] for c in myList] + + win_str_one = [s.split(" | ")[0] for s in card] + sto_str_one = [s.split(" | ")[1] for s in card] + + win_str = [s.split(" ") for s in win_str_one] + sto_str = [s.split(" ") for s in sto_str_one] + + win = [ [int(i) for i in item if i != ''] for item in win_str] + sto = [ [int(i) for i in item if i != ''] for item in sto_str] + + copy = [1] * len(win) + + for idx, p in enumerate(sto): + n = 0 + for j in p: + if win[idx].count(j) > 0: + copy[idx+n+1]+= copy[idx] + n+=1 + + return reduce(lambda x, y: x+y, copy) + +if __name__ == '__main__': + print(main(sys.stdin.read().splitlines())) \ No newline at end of file