#!/usr/bin/env python3 # -*- coding: utf-8 -*- file = "./input.txt" #file = "./ex.txt" from time import time start_time = time() keypad=[[1,2,3],[4,5,6],[7,8,9]] def read_file(f:str) -> list: out = [] input_file = open(f, "r") for line in input_file: line = line.strip() if line == "": continue else: line = line.strip() out.append(line) input_file.close() return out if __name__ == "__main__": x, y = 1, 1 part2 = True input_list = read_file(file) print("Solution: ",end="") for elem in input_list: for b in elem: if b == "R" and y < 2: y += 1 elif b == "L" and y > 0: y -= 1 elif b == "U" and x > 0: x -= 1 elif b == "D" and x < 2: x += 1 print(keypad[x][y],end="") print() # print(input_list) print(f'Runtime: {time()-start_time:.2f} s')