updated day05
This commit is contained in:
55
day05/module.py
Normal file
55
day05/module.py
Normal file
@@ -0,0 +1,55 @@
|
||||
from aoc.input import get_input
|
||||
import re
|
||||
from aoc.partselector import part_one, part_two
|
||||
|
||||
def pw(line):
|
||||
return line.strip()
|
||||
|
||||
def p1():
|
||||
inp = get_input(pw)
|
||||
count = 0
|
||||
passes = []
|
||||
for i in inp:
|
||||
index = 64
|
||||
pos = 63
|
||||
for l in i[:6]:
|
||||
if l == 'B':
|
||||
pos = pos + index/2
|
||||
if l == 'F':
|
||||
pos = pos - index/2
|
||||
index = index//2
|
||||
index2 = 4
|
||||
pos2 = 3
|
||||
positions = {
|
||||
'LLL': 0,
|
||||
'LLR': 1,
|
||||
'LRL': 2,
|
||||
'LRR': 3,
|
||||
'RLL': 4,
|
||||
'RLR': 5,
|
||||
'RRL': 6,
|
||||
'RRR': 7,
|
||||
}
|
||||
pos2 = positions[i[7:]]
|
||||
passes.append(pos * 8 + pos2 )
|
||||
|
||||
print(max(passes))
|
||||
return passes
|
||||
|
||||
|
||||
def p2(result1):
|
||||
passes = sorted(result1)
|
||||
last = 0
|
||||
last2 = 0
|
||||
for p in range(len(passes)-2):
|
||||
if passes[p] == passes[p+1] - 1 and passes[p] == passes[p+2] - 2:
|
||||
print(passes[p])
|
||||
break
|
||||
return passes
|
||||
|
||||
if part_one():
|
||||
result1 = p1()
|
||||
|
||||
|
||||
if part_two():
|
||||
p2(result1)
|
||||
Reference in New Issue
Block a user