From 0b0beccdf0142333e5db3e80cce3f8efc0c9e368 Mon Sep 17 00:00:00 2001 From: Fedor Lyanguzov Date: Tue, 13 Dec 2022 11:56:47 +0300 Subject: [PATCH] 13 --- 13/13.py | 59 ++++++++ 13/input | 449 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 508 insertions(+) create mode 100644 13/13.py create mode 100644 13/input diff --git a/13/13.py b/13/13.py new file mode 100644 index 0000000..6a271b1 --- /dev/null +++ b/13/13.py @@ -0,0 +1,59 @@ + +with open('input') as file: + packets = list(tuple(map(eval, x.split('\n'))) for x in file.read().strip().split('\n\n')) + + +def is_int(x): + return isinstance(x, int) +def is_list(x): + return isinstance(x, list) + +def compare_packets(l, r): + def compare(left, right): + nonlocal result, done + if not done: + if is_int(left) and is_int(right): + if left>right: + result = False + done = True + elif left