-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday_25.py
75 lines (59 loc) · 1.68 KB
/
day_25.py
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
from utils_py import aoc_comm, create_test_file
import os
from typing import Optional
import re
# --- update day/ year for each challenge
settings = {
'day': 25,
'year': 2022,
'cookie-path': os.path.realpath('../aoc_cookie.json')
}
# -- OTHER LIBs that might help while coding the solutions
from collections import Counter, defaultdict
from math import *
import functools
import itertools
def parse_input(inp_content):
inp_content = inp_content.strip()
# add further input processing here..
inp_content = [e for e in inp_content.split("\n")]
return inp_content
def convert_to_int(s):
n = 0
for c in s:
n *= 5
if c == '=':
n -= 2
elif c == '-':
n -= 1
else:
n += int(c)
return n
def convert_to_str(n):
s = ""
pow5 = 1
while n > 0:
for i in range(-2, 3):
if (n - (i * 5**(pow5-1))) % 5 ** pow5 == 0:
if i == -2:
s += '='
elif i == -1:
s += '-'
else:
s += str(i)
n -= i * 5**(pow5-1)
break
pow5 += 1
return s[::-1]
@aoc_comm(settings, level=1)
def solve_l1(input_str) -> Optional[int]: # input data will be passed to this as string
inp = parse_input(input_str)
ans = 0
for ee in inp:
ans += convert_to_int(ee)
return convert_to_str(ans) # if 'ans' is None answer won't be submitted, else it will submit after confirmation
def main():
# create_test_file(settings, int(input("Test file for level: ")), input("Test result: ").strip())
solve_l1()
if __name__ == '__main__':
main()