111 lines
2.5 KiB
Python
111 lines
2.5 KiB
Python
#!/bin/python3
|
|
import sys,re
|
|
from pprint import pprint
|
|
sys.path.insert(0, '../../')
|
|
from fred import list2int
|
|
|
|
input_f = 'input'
|
|
|
|
part = 2
|
|
#########################################
|
|
# #
|
|
# Part 1 #
|
|
# #
|
|
#########################################
|
|
|
|
if part == 1:
|
|
result = 0
|
|
arr = []
|
|
l = 101
|
|
for i in range(0,l):
|
|
arr.append([])
|
|
for j in range(0,l):
|
|
arr[i].append('O')
|
|
|
|
start=int((l-1)/2)
|
|
|
|
X = start
|
|
Y = start
|
|
|
|
with open(input_f) as file:
|
|
for line in file:
|
|
tmp = list(line.rstrip())
|
|
arr[X][Y] = 'X'
|
|
for idx,i in enumerate(tmp):
|
|
if i == '^':
|
|
Y -= 1
|
|
if i == '>':
|
|
X += 1
|
|
if i == '<':
|
|
X -= 1
|
|
if i == 'v':
|
|
Y += 1
|
|
|
|
arr[X][Y] = 'X'
|
|
|
|
for idx,i in enumerate(arr):
|
|
for jdx,j in enumerate(i):
|
|
if arr[idx][jdx] == 'X':
|
|
result += 1
|
|
print(result)
|
|
|
|
|
|
|
|
|
|
#########################################
|
|
# #
|
|
# Part 2 #
|
|
# #
|
|
#########################################
|
|
if part == 2:
|
|
result = 0
|
|
arr = []
|
|
l = 101
|
|
for i in range(0,l):
|
|
arr.append([])
|
|
for j in range(0,l):
|
|
arr[i].append('O')
|
|
|
|
start=int((l-1)/2)
|
|
|
|
X = start
|
|
Y = start
|
|
|
|
rX = start
|
|
rY = start
|
|
|
|
with open(input_f) as file:
|
|
for line in file:
|
|
tmp = list(line.rstrip())
|
|
arr[X][Y] = 'X'
|
|
arr[rX][rY] = 'X'
|
|
for idx,i in enumerate(tmp):
|
|
if idx % 2 == 0:
|
|
if i == '^':
|
|
Y -= 1
|
|
if i == '>':
|
|
X += 1
|
|
if i == '<':
|
|
X -= 1
|
|
if i == 'v':
|
|
Y += 1
|
|
else:
|
|
if i == '^':
|
|
rY -= 1
|
|
if i == '>':
|
|
rX += 1
|
|
if i == '<':
|
|
rX -= 1
|
|
if i == 'v':
|
|
rY += 1
|
|
|
|
arr[X][Y] = 'X'
|
|
arr[rX][rY] = 'X'
|
|
|
|
for idx,i in enumerate(arr):
|
|
for jdx,j in enumerate(i):
|
|
if arr[idx][jdx] == 'X':
|
|
result += 1
|
|
print(result)
|
|
|