71 lines
1.4 KiB
Python
Executable File
71 lines
1.4 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
from enum import Enum, IntEnum
|
|
import numpy as np
|
|
|
|
|
|
class Direction(Enum):
|
|
Up = (-1, 0)
|
|
Down = (1, 0)
|
|
Left = (0, -1)
|
|
Right = (0, 1)
|
|
|
|
|
|
class Character(Enum):
|
|
Void = ord(' ')
|
|
Vertical = ord('|')
|
|
Horizontal = ord('-')
|
|
Corner = ord('+')
|
|
Letter = -1
|
|
|
|
|
|
def parse_char(char):
|
|
try:
|
|
Character(char)
|
|
except:
|
|
assert chr(char).isalpha(), 'Unknown character {}'.format(chr(char))
|
|
return Character.Letter
|
|
|
|
|
|
class Packet(object):
|
|
|
|
def __init__(self, schema):
|
|
self.schema = np.array(map(lambda x: map(ord, x), schema))
|
|
self.x = 0
|
|
self.y = np.where(self.schema[0] == Character.Vertical.value)[0,0]
|
|
self.direction = Direction.Down
|
|
|
|
def __iter__(self):
|
|
return self
|
|
|
|
def __next__(self):
|
|
self.forward()
|
|
while self.current_char != Character.Letter:
|
|
self.forward()
|
|
return self.current_char
|
|
|
|
@property
|
|
def position(self):
|
|
return (self.x, self.y)
|
|
|
|
@position.setter
|
|
def set_position(self, value):
|
|
self.x, self.y = value
|
|
|
|
@property
|
|
def current_char(self):
|
|
return parse_char(self.schema[self.position])
|
|
|
|
def peek(self):
|
|
return parse_char(self.schema[self.position + self.direction.value])
|
|
|
|
def forward(self):
|
|
pass
|
|
|
|
def main():
|
|
import fileinput
|
|
p = Packet(fileinput.input())
|
|
print(''.join(p))
|
|
|
|
if __name__ == '__main__':
|
|
main()
|