1
0
Fork 0

2017 day 19, WIP

This commit is contained in:
Lucidiot 2020-12-07 02:42:38 +01:00
parent 5cd65e1125
commit b8ffad6c79
Signed by: lucidiot
GPG Key ID: 3358C1CA6906FB8D
2 changed files with 71 additions and 0 deletions

70
2017/19/packet.py Executable file
View File

@ -0,0 +1,70 @@
#!/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()

1
2017/19/requirements.txt Normal file
View File

@ -0,0 +1 @@
numpy>=1.15