-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# 2018 AoC | ||
|
||
Solutions to 2018 AoC in Python. | ||
|
||
## Template generator | ||
|
||
A generator is included in [setup.py](https://github.com/TimHi/AdventOfCode/blob/main/Python/2018/setup.py). Running the script will create a new folder with the trailing number of the most recent day. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import os | ||
import re | ||
import shutil | ||
|
||
def trailing_number(d): | ||
m = re.search(r'\d+$', d) | ||
return int(m.group()) if m else int(0) | ||
|
||
def get_most_recent_day(path): | ||
filtered_directories = list(filter(lambda f : os.path.isdir(f) and f != '.idea' and f != 'template',os.listdir(current_path))) | ||
filtered_directories.sort(key=trailing_number) | ||
if len(filtered_directories) == 0: | ||
return 0 | ||
else: | ||
return trailing_number(filtered_directories[-1]) | ||
|
||
current_path = os.path.dirname(os.path.realpath(__file__)) | ||
most_recent_day = get_most_recent_day(current_path) + 1 | ||
|
||
base_path = current_path + '/' | ||
day_str = 'day' + str(most_recent_day) | ||
new_path = base_path + '/' +str(day_str) | ||
if not os.path.exists(new_path): | ||
os.makedirs(new_path) | ||
shutil.copyfile(current_path + '\\template\\template.py', new_path +'\\'+ day_str + '.py') | ||
shutil.copyfile(current_path + '\\template\\template.py', new_path + '\\' + 'example01.txt') | ||
shutil.copyfile(current_path + '\\template\\template.py', new_path + '\\' + 'example02.txt') | ||
else: | ||
raise ValueError(f'Trying to create directory {base_path} but is already existing') | ||
|
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import pathlib | ||
import sys | ||
import os | ||
|
||
def format_input(raw_data): | ||
return "" | ||
|
||
def part1(data): | ||
return "" | ||
|
||
def part2(data): | ||
return "" | ||
|
||
def solve(raw_01, raw_02): | ||
data_01 = format_input(raw_01) | ||
data_02 = format_input(raw_02) | ||
solution1 = part1(data_01) | ||
solution2 = part2(data_02) | ||
return solution1, solution2 | ||
|
||
|
||
def setup_and_solve(): | ||
current_path = os.path.dirname(os.path.realpath(__file__)) | ||
|
||
read_raw_01 = pathlib.Path(current_path + '/example01.txt').read_text().strip() | ||
read_raw_02 = pathlib.Path(current_path + '/example02.txt').read_text().strip() | ||
|
||
solutions = solve(read_raw_01,read_raw_02) | ||
print("\n".join(str(solution) for solution in solutions)) | ||
|
||
setup_and_solve() |