Skip to content

Commit

Permalink
setup template generator
Browse files Browse the repository at this point in the history
  • Loading branch information
TimHi committed Nov 10, 2024
1 parent 6e4917e commit e11006e
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 0 deletions.
Binary file removed .DS_Store
Binary file not shown.
1 change: 1 addition & 0 deletions Python/2018/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.idea
7 changes: 7 additions & 0 deletions Python/2018/README.md
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.
30 changes: 30 additions & 0 deletions Python/2018/setup.py
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.
31 changes: 31 additions & 0 deletions Python/2018/template/template.py
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()

0 comments on commit e11006e

Please sign in to comment.