Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
fschatbot committed Dec 11, 2024
2 parents 6c7246c + 69c756c commit 1e60603
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 9 deletions.
78 changes: 78 additions & 0 deletions 2023/21.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from typing import List, Tuple

def parse(data):
starting = None
walls = []

for y, line in enumerate(data.split('\n')):
for x, char in enumerate(line):
if char == '#': walls.append((x, y))
if char == 'S': starting = x, y

return walls, starting, (len(data.split('\n')[0]), len(data.split('\n')))

split_data = parse
completed = 1
raw_data = None # Not To be touched

class DIRECTION:
UP = [0, -1]
DOWN = [0, +1]
LEFT = [-1, 0]
RIGHT = [+1, 0]


def prettyPrint(walls, mx, my, new_at):
for y in range(my):
string = ''
for x in range(mx):
if (x, y) in new_at:
string += 'O'
elif (x, y) in walls:
string += '#'
else:
string += '.'

print(string)
print()

def part1(data:Tuple[List[Tuple[int, int]], Tuple[int, int]]):
walls, starting, mapsize = data
mx, my = mapsize


at = set()
new_at = set([starting])
for _ in range(64):
at = new_at
new_at = set()

for x, y in at:
for dx, dy in [DIRECTION.UP, DIRECTION.DOWN, DIRECTION.LEFT, DIRECTION.RIGHT]:
nx, ny = x + dx, y + dy
if not (0 <= nx < mx and 0 <= ny < my): continue
if (nx, ny) in walls: continue
new_at.add((nx, ny))

prettyPrint(walls, mx, my, new_at)

return len(new_at)

def part2(data:List[str]):
# I think the trick to this is waiting for any one of the tiles the elf can be present at any given moment.
# After this the adjecent tiles will be filled no matter the given step.
# 2. We can find this tile by checking if the tile was present in the "at" set 2 times
# Mathematical Approch
# We just need to find the amount of unique tiles it can reach by the end of 26501365 steps
# Then return ans // 2 and we should be done. (Approximate)
# Brute Approch
# Figure out at which point after spreading indefinately does the the grid begin to repeat.
# 2. When that happens we win
# Elegant Approch:
# Note: After the elf reach a point for the first time the elf can reach that step every other time!
# Hence, after a point the grid will simply start repeating itself. The on will become off and the off will become on
# Hence, we need to find a place only once and never ever think about it again.
...
10 changes: 5 additions & 5 deletions Completed.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

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

Parts Completed: 291/500 (58.20%)
Parts Completed: 294/500 (58.80%)
<br>
Days Completed: 143/250 (57.20%)
Days Completed: 144/250 (57.60%)
<br>
Lines of code: 8065
Lines of code: 8150

### Legend

Expand All @@ -18,8 +18,8 @@ Lines of code: 8065
||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|
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|**2024**||||||🚫|🚫|🚫|🚫|🚫|🚫|🚫|🚫|🚫|🚫|🚫|🚫|🚫|🚫|🚫|🚫|🚫|🚫|🚫|🚫|
|**2023**|||||½|||||||🚫|||||🚫|🚫||🚫|🚫|🚫|🚫|🚫|🚫|
|**2022**||||||||🚫|||½|🚫|🚫||🚫|🚫|🚫||🚫|🚫||½||🚫|🚫|
|**2023**|||||½|||||||🚫|||||🚫|🚫||🚫|½|🚫|🚫|🚫|🚫|
|**2022**||||||||🚫|||½|🚫|🚫||🚫|🚫|🚫||🚫|🚫||½||🚫||
|**2021**||||||||||||🚫||||🚫|🚫|🚫|🚫|🚫|🚫|🚫|🚫|🚫|🚫|
|**2020**||||||||||🚫||🚫|🚫|||🚫|🚫|🚫|🚫|🚫|🚫|🚫|🚫|🚫|🚫|
|**2019**||||||||||||||||🚫|🚫|🚫|🚫|🚫|🚫|🚫|🚫|🚫|🚫|
Expand Down
2 changes: 1 addition & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def collect_data(force) -> None:
makedirs(folder_path+'inputs')
except FileExistsError:
pass
response = requests.get(f'https://adventofcode.com/{args.year}/day/{args.day}/input', cookies={'session':config.session_cookie})
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'})
raw_data = response.text.strip('\n')
# Save the data for backup
if response.status_code == 200:
Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Then you can run the script with the following command:

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

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.
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

## Journey of advent calendar

Expand Down
6 changes: 4 additions & 2 deletions runner_template.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from typing import List

split_data = True
completed = False
raw_data = None # Not To be touched

def part1(data):
def part1(data:List[str]):
...

def part2(data):
def part2(data:List[str]):
...

0 comments on commit 1e60603

Please sign in to comment.