Skip to content

Commit 1e60603

Browse files
committed
2 parents 6c7246c + 69c756c commit 1e60603

File tree

5 files changed

+89
-9
lines changed

5 files changed

+89
-9
lines changed

2023/21.py

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
4+
from typing import List, Tuple
5+
6+
def parse(data):
7+
starting = None
8+
walls = []
9+
10+
for y, line in enumerate(data.split('\n')):
11+
for x, char in enumerate(line):
12+
if char == '#': walls.append((x, y))
13+
if char == 'S': starting = x, y
14+
15+
return walls, starting, (len(data.split('\n')[0]), len(data.split('\n')))
16+
17+
split_data = parse
18+
completed = 1
19+
raw_data = None # Not To be touched
20+
21+
class DIRECTION:
22+
UP = [0, -1]
23+
DOWN = [0, +1]
24+
LEFT = [-1, 0]
25+
RIGHT = [+1, 0]
26+
27+
28+
def prettyPrint(walls, mx, my, new_at):
29+
for y in range(my):
30+
string = ''
31+
for x in range(mx):
32+
if (x, y) in new_at:
33+
string += 'O'
34+
elif (x, y) in walls:
35+
string += '#'
36+
else:
37+
string += '.'
38+
39+
print(string)
40+
print()
41+
42+
def part1(data:Tuple[List[Tuple[int, int]], Tuple[int, int]]):
43+
walls, starting, mapsize = data
44+
mx, my = mapsize
45+
46+
47+
at = set()
48+
new_at = set([starting])
49+
for _ in range(64):
50+
at = new_at
51+
new_at = set()
52+
53+
for x, y in at:
54+
for dx, dy in [DIRECTION.UP, DIRECTION.DOWN, DIRECTION.LEFT, DIRECTION.RIGHT]:
55+
nx, ny = x + dx, y + dy
56+
if not (0 <= nx < mx and 0 <= ny < my): continue
57+
if (nx, ny) in walls: continue
58+
new_at.add((nx, ny))
59+
60+
prettyPrint(walls, mx, my, new_at)
61+
62+
return len(new_at)
63+
64+
def part2(data:List[str]):
65+
# I think the trick to this is waiting for any one of the tiles the elf can be present at any given moment.
66+
# After this the adjecent tiles will be filled no matter the given step.
67+
# 2. We can find this tile by checking if the tile was present in the "at" set 2 times
68+
# Mathematical Approch
69+
# We just need to find the amount of unique tiles it can reach by the end of 26501365 steps
70+
# Then return ans // 2 and we should be done. (Approximate)
71+
# Brute Approch
72+
# Figure out at which point after spreading indefinately does the the grid begin to repeat.
73+
# 2. When that happens we win
74+
# Elegant Approch:
75+
# Note: After the elf reach a point for the first time the elf can reach that step every other time!
76+
# Hence, after a point the grid will simply start repeating itself. The on will become off and the off will become on
77+
# Hence, we need to find a place only once and never ever think about it again.
78+
...

Completed.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
Over Here you can see the completion status of the project.
44

5-
Parts Completed: 291/500 (58.20%)
5+
Parts Completed: 294/500 (58.80%)
66
<br>
7-
Days Completed: 143/250 (57.20%)
7+
Days Completed: 144/250 (57.60%)
88
<br>
9-
Lines of code: 8065
9+
Lines of code: 8150
1010

1111
### Legend
1212

@@ -18,8 +18,8 @@ Lines of code: 8065
1818
||1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19|20|21|22|23|24|25|
1919
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
2020
|**2024**||||||🚫|🚫|🚫|🚫|🚫|🚫|🚫|🚫|🚫|🚫|🚫|🚫|🚫|🚫|🚫|🚫|🚫|🚫|🚫|🚫|
21-
|**2023**|||||½|||||||🚫|||||🚫|🚫||🚫|🚫|🚫|🚫|🚫|🚫|
22-
|**2022**||||||||🚫|||½|🚫|🚫||🚫|🚫|🚫||🚫|🚫||½||🚫|🚫|
21+
|**2023**|||||½|||||||🚫|||||🚫|🚫||🚫|½|🚫|🚫|🚫|🚫|
22+
|**2022**||||||||🚫|||½|🚫|🚫||🚫|🚫|🚫||🚫|🚫||½||🚫||
2323
|**2021**||||||||||||🚫||||🚫|🚫|🚫|🚫|🚫|🚫|🚫|🚫|🚫|🚫|
2424
|**2020**||||||||||🚫||🚫|🚫|||🚫|🚫|🚫|🚫|🚫|🚫|🚫|🚫|🚫|🚫|
2525
|**2019**||||||||||||||||🚫|🚫|🚫|🚫|🚫|🚫|🚫|🚫|🚫|🚫|

main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def collect_data(force) -> None:
6161
makedirs(folder_path+'inputs')
6262
except FileExistsError:
6363
pass
64-
response = requests.get(f'https://adventofcode.com/{args.year}/day/{args.day}/input', cookies={'session':config.session_cookie})
64+
response = requests.get(f'https://adventofcode.com/{args.year}/day/{args.day}/input', cookies={'session':config.session_cookie}, headers={'User-Agent': 'github.com/fschatbot/Advent-Calendar-Python/ by FSChatbot'})
6565
raw_data = response.text.strip('\n')
6666
# Save the data for backup
6767
if response.status_code == 200:

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Then you can run the script with the following command:
1818

1919
`python main.py --year [year] --day [day]`
2020

21-
Running a day that doesn't exsits will create a runner file for the day. This is a public repo meaning you can create your own answers and commit to the repo.
21+
Running a day that doesn't exsits will create a runner file for the day. This is a public repo meaning you can create your own answers and commit to the repo. This repo does follow the automation guidelines on the /r/adventofcode community wiki
2222

2323
## Journey of advent calendar
2424

runner_template.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
#!/usr/bin/env python
22
# -*- coding: utf-8 -*-
33

4+
from typing import List
5+
46
split_data = True
57
completed = False
68
raw_data = None # Not To be touched
79

8-
def part1(data):
10+
def part1(data:List[str]):
911
...
1012

11-
def part2(data):
13+
def part2(data:List[str]):
1214
...

0 commit comments

Comments
 (0)