#!/bin/python3 import sys,re from pprint import pprint sys.path.insert(0, '../../') from fred import list2int,get_re,nprint,lprint input_f = 'test' part = 1 ######################################### # # # Part 1 # # # ######################################### max_steps = 12302209 begin_state = 'A' states = { 'A': { 0: { 'W': 1, 'M': 'R', 'C': 'B' }, 1: { 'W': 0, 'M': 'L', 'C': 'D' } }, 'B': { 0: { 'W': 1, 'M': 'R', 'C': 'C' }, 1: { 'W': 0, 'M': 'R', 'C': 'F' } }, 'C': { 0: { 'W': 1, 'M': 'L', 'C': 'C' }, 1: { 'W': 1, 'M': 'L', 'C': 'A' } }, 'D': { 0: { 'W': 0, 'M': 'L', 'C': 'E' }, 1: { 'W': 1, 'M': 'R', 'C': 'A' } }, 'E': { 0: { 'W': 1, 'M': 'L', 'C': 'A' }, 1: { 'W': 0, 'M': 'R', 'C': 'B' } }, 'F': { 0: { 'W': 0, 'M': 'R', 'C': 'C' }, 1: { 'W': 0, 'M': 'R', 'C': 'E' } } } # print(states) # max_steps = 6 # begin_state = 'A' # states = { # 'A': { # 0: { # 'W': 1, # 'M': 'R', # 'C': 'B' # }, # 1: { # 'W': 0, # 'M': 'L', # 'C': 'B' # } # }, # 'B': { # 0: { # 'W': 1, # 'M': 'L', # 'C': 'A' # }, # 1: { # 'W': 1, # 'M': 'R', # 'C': 'A' # } # } # } if part == 1: end = False steps = 0 line = [0,0,0,0,0,0,0,0,0] idx = 4 state = begin_state while not end: if idx-1 <= 0: line.insert(0, [0]) idx += 1 if idx+2 > len(line): line.append(0) line.append(0) cur = line[idx] line[idx] = states[state][cur]['W'] if states[state][cur]['M'] == 'L': idx -= 1 else: idx += 1 state = states[state][cur]['C'] steps += 1 if steps == max_steps: end = True print(line.count(1)) ######################################### # # # Part 2 # # # ######################################### if part == 2: exit()