From 264496e0e16fa59f976ff7e988f011cc19ea0d2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Jos=C3=A9=20Guti=C3=A9rrez=20de=20Quevedo=20P=C3=A9?= =?UTF-8?q?rez?= Date: Tue, 22 Dec 2020 23:01:35 +0100 Subject: [PATCH] day 22 part 1 --- 22/1.py | 41 +++++++++++++++++++++++++++++++++++++++++ 22/input | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 94 insertions(+) create mode 100644 22/1.py create mode 100644 22/input diff --git a/22/1.py b/22/1.py new file mode 100644 index 0000000..f00653f --- /dev/null +++ b/22/1.py @@ -0,0 +1,41 @@ +with open("input") as f: + content = [x.strip() for x in f] + +player1 = [] +player2 = [] +part = 0 +for c in content: + if not c: + part += 1 + continue + if part == 0: # reading player 2 stack + if c.startswith("Player"): + continue + player1.append(int(c)) + if part == 1: # reading player 1 stack + if c.startswith("Player"): + continue + player2.append(int(c)) + +while len(player1) and len(player2): + if player1[0] > player2[0]: + player1.append(player1[0]) + player1.append(player2[0]) + del(player1[0]) + del(player2[0]) + else: + player2.append(player2[0]) + player2.append(player1[0]) + del(player1[0]) + del(player2[0]) + +if len(player1): + winner = player1 +else: + winner = player2 + +result = 0 +for i in range(len(winner)): + result += (len(winner) - i ) * winner[i] + +print(result) diff --git a/22/input b/22/input new file mode 100644 index 0000000..62dc0e5 --- /dev/null +++ b/22/input @@ -0,0 +1,53 @@ +Player 1: +29 +21 +38 +30 +25 +7 +2 +36 +16 +44 +20 +12 +45 +4 +31 +34 +33 +42 +50 +14 +39 +37 +11 +43 +18 + +Player 2: +32 +24 +10 +41 +13 +3 +6 +5 +9 +8 +48 +49 +46 +17 +22 +35 +1 +19 +23 +28 +40 +26 +47 +15 +27