Skip to content

Commit 8caf384

Browse files
committed
Completed day 25 of year 2022
1 parent 2bdca2e commit 8caf384

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

2022/25.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
4+
split_data = True
5+
completed = True
6+
raw_data = None # Not To be touched
7+
8+
def part1(data):
9+
charMap = {'=':-2, '-':-1, '0':0, '1':1, '2':2}
10+
def SNAFUtoDECIMAL(snafu):
11+
return sum(5**(len(snafu)-p)*charMap[num] for p, num in enumerate(snafu, start=1))
12+
13+
total = sum(SNAFUtoDECIMAL(line) for line in data)
14+
print("Total Fuel:", total)
15+
16+
# Now comes the hard part
17+
SNAFU = []
18+
19+
while total > SNAFUtoDECIMAL(SNAFU):
20+
SNAFU.append('2')
21+
22+
l = ['2', '1', '0', '-', '=']
23+
24+
for index in range(len(SNAFU)):
25+
for a in l:
26+
if SNAFUtoDECIMAL(SNAFU[:index]+[a]+SNAFU[index+1:]) - total < 0: break
27+
SNAFU[index] = a
28+
29+
return ''.join(SNAFU)
30+
31+
def part2(data):
32+
...

0 commit comments

Comments
 (0)