Reorganized the repository

This commit is contained in:
Tiago Garcia 2023-06-05 22:09:32 +01:00
parent 026a6303be
commit 8596c316cf
No known key found for this signature in database
GPG Key ID: F423E37A2415E160
61 changed files with 3220 additions and 42 deletions

25
2022/day7/day7.py Normal file
View File

@ -0,0 +1,25 @@
def main():
directory_contents = {}
with open('input.txt', 'r') as f:
input_lines = f.readlines()
line_index = 0
while line_index < len(input_lines):
if input_lines[line_index].startswith('$ cd'):
if input_lines[line_index][5:] not in ['..', '/']:
directory_contents[input_lines[line_index][5:]] = []
line_index += 1
continue
elif input_lines[line_index].startswith('$ ls'):
line_index += 1
while not input_lines[line_index].startswith('$'):
...
def current_dir_size(dir: str) -> int:
...
if __name__ == "__main__":
main()

1087
2022/day7/input.txt Normal file

File diff suppressed because it is too large Load Diff

99
2022/day9/day9_part1.py Normal file
View File

@ -0,0 +1,99 @@
def main():
with open('input.txt', 'r') as f:
head_moves = f.readlines()
head_moves = [move.split() for move in head_moves]
head_pos, tail_pos = [0,0], [0,0]
pos_list = []
for move in head_moves:
pos_list.append(tuple(tail_pos))
if move[0] == 'U':
for i in range(int(move[1])):
head_pos[1] += 1
if validate_pos(head_pos, tail_pos):
pos_list.append(tuple(tail_pos))
continue
if head_pos[0] == tail_pos[0]:
tail_pos[1] += 1
pos_list.append(tuple(tail_pos))
elif head_pos[0] == tail_pos[0] + 1:
tail_pos[1] += 1
pos_list.append(tuple(tail_pos))
tail_pos[0] += 1
pos_list.append(tuple(tail_pos))
elif head_pos[0] == tail_pos[0] - 1:
tail_pos[1] += 1
pos_list.append(tuple(tail_pos))
tail_pos[0] -= 1
pos_list.append(tuple(tail_pos))
elif move[0] == 'D':
for i in range(int(move[1])):
head_pos[1] -= 1
if validate_pos(head_pos, tail_pos):
pos_list.append(tuple(tail_pos))
continue
if head_pos[0] == tail_pos[0]:
tail_pos[1] -= 1
pos_list.append(tuple(tail_pos))
elif head_pos[0] == tail_pos[0] + 1:
tail_pos[1] -= 1
pos_list.append(tuple(tail_pos))
tail_pos[0] += 1
pos_list.append(tuple(tail_pos))
elif head_pos[0] == tail_pos[0] - 1:
tail_pos[1] -= 1
pos_list.append(tuple(tail_pos))
tail_pos[0] -= 1
pos_list.append(tuple(tail_pos))
elif move[0] == 'R':
for i in range(int(move[1])):
head_pos[0] += 1
if validate_pos(head_pos, tail_pos):
pos_list.append(tuple(tail_pos))
continue
if head_pos[1] == tail_pos[1]:
tail_pos[0] += 1
pos_list.append(tuple(tail_pos))
elif head_pos[1] == tail_pos[1] + 1:
tail_pos[0] += 1
pos_list.append(tuple(tail_pos))
tail_pos[1] += 1
pos_list.append(tuple(tail_pos))
elif head_pos[1] == tail_pos[1] - 1:
tail_pos[0] += 1
pos_list.append(tuple(tail_pos))
tail_pos[1] -= 1
pos_list.append(tuple(tail_pos))
elif move[0] == 'L':
for i in range(int(move[1])):
head_pos[0] -= 1
if validate_pos(head_pos, tail_pos):
pos_list.append(tuple(tail_pos))
continue
if head_pos[1] == tail_pos[1]:
tail_pos[0] -= 1
pos_list.append(tuple(tail_pos))
elif head_pos[1] == tail_pos[1] + 1:
tail_pos[0] -= 1
pos_list.append(tuple(tail_pos))
tail_pos[1] += 1
pos_list.append(tuple(tail_pos))
elif head_pos[1] == tail_pos[1] - 1:
tail_pos[0] -= 1
pos_list.append(tuple(tail_pos))
tail_pos[1] -= 1
pos_list.append(tuple(tail_pos))
pos_set = set(pos_list)
pos_list = list(pos_set)
print(len(pos_list))
#print(f"Repeated positions: {pos_count}")
def validate_pos(h: list[int], t: list[int]) -> bool:
return -2 < h[0] - t[0] < 2 and -2 < h[1] - t[1] < 2
if __name__ == "__main__":
main()

2000
2022/day9/input.txt Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,15 +1,11 @@
# Advent of Code 2022
### Solutions for the 2022 AoC challenges
# Advent of Code
## Solutions for the AoC Challenges
### They might not be the best solutions but they work and that's the important part of a coders job :xdd:
---
## Languages used:
#### Python:
* Day 1
* Day 2
* Day 4
* Day 5
* Day 6
* Day 8
#### C#:
* Day 3
---
## Languages used by days:
### 2022
| Language | Days |
|----------|------------------|
| Python | 1, 2, 4, 5, 6, 8 |
| C# | 3 |

View File

@ -1,29 +0,0 @@
import os
from datetime import date
def main(args):
currentDay = date.today().day
reposDirectory = f"/home/{os.getlogin()}/repos/advent-of-code-2022"
dayGroups = [(int(days[4:].split('-')[0]), int(days[4:].split('-')[1])) for days in [directory for directory in os.listdir(reposDirectory) if directory.startswith('days')][::-1]]
indexOfDayGroup = -1
for dayGroup in dayGroups:
if dayGroup[0] < currentDay < dayGroup[1]:
indexOfDayGroup = dayGroups.index(dayGroup)
break
currentDayGroupDir = f"{reposDirectory}/days{dayGroups[indexOfDayGroup][0]}-{dayGroups[indexOfDayGroup][1]}"
currentDayDir = f"{currentDayGroupDir}/day{currentDay}"
if len(args) > 1:
if args[1] == "run":
os.system(f"python3 {currentDayDir}/day{currentDay}.py")
return
if f"day{currentDay}" not in os.listdir(currentDayGroupDir):
os.system(f"mkdir {currentDayDir}")
os.system(f"vim {currentDayDir}/day{currentDay}.py")
import sys
if __name__ == "__main__":
main(sys.argv)