#!/bin/python3 import sys,re from pprint import pprint sys.path.insert(0, '../../') from fred import list2int,get_value_in_direction input_f = 'input' ######################################### # # # Part 1+2 # # # ######################################### grid = [] with open(input_f) as file: for line in file: grid.append(line.rstrip()) start = (0,grid[0].index('|')) dir = (1,0) visited = [] cur = start count = 1 while get_value_in_direction(grid,cur) != 'S': # last letter in my input new = (cur[0]+dir[0],cur[1]+dir[1]) if get_value_in_direction(grid,new) != ' ': cur = new count += 1 if get_value_in_direction(grid,cur).isalpha(): visited.append(get_value_in_direction(grid,cur)) if get_value_in_direction(grid,cur) == '+': if get_value_in_direction(grid,cur,'right') == '-' and dir[1] != -1: dir = (0,1) continue if get_value_in_direction(grid,cur,'left') == '-' and dir[1] != 1: dir = (0,-1) continue if get_value_in_direction(grid,cur,'up') == '|' and dir[0] != 1: dir = (-1,0) continue if get_value_in_direction(grid,cur,'down') == '|' and dir[0] != -1: dir = (1,0) continue for i in visited: print(i,end='') print() print(count)