day 1
This commit is contained in:
commit
daa6077257
|
|
@ -0,0 +1 @@
|
||||||
|
.vs
|
||||||
|
|
@ -0,0 +1,15 @@
|
||||||
|
import aocd
|
||||||
|
|
||||||
|
def main(data):
|
||||||
|
password = 0
|
||||||
|
dial = 50
|
||||||
|
for line in data.strip().split('\n'):
|
||||||
|
dial = (dial + int(line.replace(*'L-').replace(*'R '))) % 100
|
||||||
|
password += not dial
|
||||||
|
return password
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
solution = main(aocd.get_data(day=1, year=2025))
|
||||||
|
print(solution)
|
||||||
|
aocd.submit(solution, part='a', day=1, year=2025)
|
||||||
|
|
@ -0,0 +1,20 @@
|
||||||
|
import aocd
|
||||||
|
|
||||||
|
def main(data):
|
||||||
|
password = 0
|
||||||
|
dial = 50
|
||||||
|
for line in data.strip().split('\n'):
|
||||||
|
turn = int(line.replace(*'L-').replace(*'R '))
|
||||||
|
neg = turn < 0
|
||||||
|
password += abs(turn) // 100
|
||||||
|
turn = abs(turn) % 100
|
||||||
|
for _ in range(turn):
|
||||||
|
dial = (dial + neg*2-1) % 100
|
||||||
|
password += not dial
|
||||||
|
return password
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
solution = main(aocd.get_data(day=1, year=2025))
|
||||||
|
print(solution)
|
||||||
|
aocd.submit(solution, part='b', day=1, year=2025)
|
||||||
|
|
@ -0,0 +1,43 @@
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
|
def get_template(year, day, part):
|
||||||
|
part_letter = {1: 'a', 2: 'b'}[part]
|
||||||
|
|
||||||
|
return f'''import aocd
|
||||||
|
|
||||||
|
def main(data):
|
||||||
|
...
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
solution = main(aocd.get_data(day={day}, year={year}))
|
||||||
|
print(solution)
|
||||||
|
# aocd.submit(solution, part='{part_letter}', day={day}, year={year})'''
|
||||||
|
|
||||||
|
def main():
|
||||||
|
today = datetime.today()
|
||||||
|
|
||||||
|
year = today.year
|
||||||
|
month = today.month
|
||||||
|
day = today.day if len(sys.argv) == 1 else int(sys.argv[1])
|
||||||
|
|
||||||
|
if month != 12 or not 1 <= day <= 25:
|
||||||
|
print('Advent of Code runs from December 1st to December 25th', file=sys.stderr)
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
directory_name = f'day-{day:02}'
|
||||||
|
if directory_name not in os.listdir():
|
||||||
|
os.mkdir(directory_name)
|
||||||
|
|
||||||
|
for part in (1, 2):
|
||||||
|
filename = f'part-{part}.py'
|
||||||
|
|
||||||
|
if filename in os.listdir(directory_name):
|
||||||
|
continue
|
||||||
|
|
||||||
|
with open(f'{directory_name}/{filename}', 'w') as f:
|
||||||
|
f.write(get_template(year, day, part))
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
||||||
Loading…
Reference in New Issue