Skip to content

Commit b155e59

Browse files
committed
AoC
1 parent fd8dbe6 commit b155e59

File tree

7 files changed

+250
-2
lines changed

7 files changed

+250
-2
lines changed

.img/2023/04.png

8.29 KB
Loading

2023/04/input.txt

Lines changed: 209 additions & 0 deletions
Large diffs are not rendered by default.

2023/04/main.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import re
2+
3+
with open('input.txt') as file:
4+
lines = file.read().strip().splitlines()
5+
6+
part1 = 0
7+
part2_cards = [1 for _ in range(len(lines))]
8+
for line in lines:
9+
x = line.split('|')
10+
game, *winning = list(map(int, re.findall(r'\d+', x[0])))
11+
my_cards = list(map(int, re.findall(r'\d+', x[1])))
12+
13+
matches = 0
14+
for match in my_cards:
15+
if match in winning:
16+
matches += 1
17+
part1 += int(2 ** (matches - 1))
18+
for i in range(game, game + matches):
19+
part2_cards[i] += part2_cards[game - 1]
20+
21+
print(part1)
22+
print(sum(part2_cards))

2023/04/test.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Card 1: 41 48 83 86 17 | 83 86 6 31 17 9 48 53
2+
Card 2: 13 32 20 16 61 | 61 30 68 82 17 32 24 19
3+
Card 3: 1 21 53 59 44 | 69 82 63 72 16 21 14 1
4+
Card 4: 41 92 73 84 69 | 59 84 76 51 58 5 54 83
5+
Card 5: 87 83 26 28 32 | 88 30 70 12 93 22 82 36
6+
Card 6: 31 18 13 56 72 | 74 77 10 23 35 67 36 11

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
</h2>
99
<!-- AOC TILES BEGIN -->
1010
<h1 align="center">
11-
2023 - 6
11+
2023 - 8
1212
</h1>
1313
<a href="2023/01/main.py">
1414
<img src=".img/2023/01.png" width="161px">
@@ -19,6 +19,9 @@
1919
<a href="2023/03/main.py">
2020
<img src=".img/2023/03.png" width="161px">
2121
</a>
22+
<a href="None">
23+
<img src=".img/2023/04.png" width="161px">
24+
</a>
2225
<h1 align="center">
2326
2022 - 48 ⭐
2427
</h1>

new_day.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import os
55

66
day, year = datetime.today().strftime('%d'), datetime.today().strftime('%Y')
7-
path = f'{year}/03'
7+
path = f'{year}/{day}'
88
if not os.path.exists(path):
99
os.makedirs(path)
1010

template.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
from aocd import submit
22
from aocd.models import Puzzle
33
from datetime import datetime
4+
import re
5+
import collections
6+
import itertools
7+
from copy import deepcopy
8+
import math
9+
import heapq
10+
import string
11+
from functools import cmp_to_key as c2k
412

513
EXAMPLE = True
614
PART = 1

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy