53 lines
1.1 KiB
Python
53 lines
1.1 KiB
Python
import itertools
|
|
|
|
def half(list, direction):
|
|
length = len(list)
|
|
num = int(length / 2)
|
|
if direction == 'F' or direction == 'R':
|
|
return list[0:num]
|
|
else:
|
|
return list[num:]
|
|
|
|
def pos(directions):
|
|
rows = [i for i in range(128)]
|
|
cols = [i for i in range(8)]
|
|
for i in directions:
|
|
if i == "F" or i == "B":
|
|
rows = half(rows, i)
|
|
elif i == "L" or i == "R":
|
|
cols = half(cols, i)
|
|
return (rows[0], 7 - cols[0])
|
|
|
|
def id(coord):
|
|
return (coord[0] * 8) + coord[1]
|
|
|
|
fd = open('input', 'r')
|
|
lines = fd.readlines()
|
|
def part1():
|
|
greatest = 0
|
|
for i in lines:
|
|
i = i.rstrip()
|
|
if id(pos(i)) > greatest:
|
|
greatest = id(pos(i))
|
|
|
|
def part2():
|
|
rows = []
|
|
cols = []
|
|
|
|
grandlist = [['.' for i in range(8)] for j in range(128)]
|
|
for i in lines:
|
|
i = i.rstrip()
|
|
item = pos(i)
|
|
grandlist[item[0]][item[1]] = 'X'
|
|
|
|
print("1 2 3 4 5 6 7 8")
|
|
cnt = 1
|
|
for i in grandlist:
|
|
print(' '.join(i) + ' ' + str(cnt))
|
|
cnt += 1
|
|
|
|
# it's 81, 3 (you have to look at the chart)
|
|
print(id((80, 2)))
|
|
|
|
part2()
|