From b6ae910775c83700b742a1aef1942bcd00996ca2 Mon Sep 17 00:00:00 2001 From: FrederikBaerentsen Date: Fri, 8 Dec 2023 09:55:45 +0100 Subject: [PATCH] Working on 2023-12-08 p1 --- 2023/day8/part1.py | 81 ++++++++++++++++++++++++++++++++++++++++++++++ 2023/day8/test2 | 5 +++ 2023/day8/test3 | 9 ++++++ 3 files changed, 95 insertions(+) create mode 100644 2023/day8/part1.py create mode 100644 2023/day8/test2 create mode 100644 2023/day8/test3 diff --git a/2023/day8/part1.py b/2023/day8/part1.py new file mode 100644 index 0000000..25591ba --- /dev/null +++ b/2023/day8/part1.py @@ -0,0 +1,81 @@ +#!/bin/python3 + +import re +import sys +from pprint import pprint +from collections import Counter +import numpy as np + +input_f = sys.argv[1] + +def pp(x): + for i in x: + for j in i: + print(j) + print() + +d, *maps = open(input_f).read().split('\n') + +d = list(d) + +s = [] +l = [] +r = [] + +maps = maps + +nmaps = [] + +for i in maps: + if i == '': + continue + s = i[:3] + l = i[7:10] + r = i[12:15] + nmaps.append([s,l,r]) + + +pprint(d) +pprint(maps) +pprint(nmaps) + +count = 0 +way = nmaps[0][0] +first = True +found = False +index = 0 +print('Starting with ' + way) +while found == False: + for i in d: + print('Finding Index for ' + way,end=' at ') + c = way + #if first == False: + index = [(i,table.index(c)) for i, table in enumerate(nmaps) if c in table] + print(index,end='') + for j in index: + if list(j)[1] == 0: + index = list(j)[0] + #index = list(index[0])[1] + print(' (true index ',end='') + print(index,end=') ') + #else: + # first = False + if i == 'R': + way = nmaps[index][2] + print('Going R to ' + way) + if i == 'L': + way = nmaps[index][1] + print('Going L to ' + way) + count += 1 + if way == 'ZZZ': + found = True + continue + #if nmaps[index][1] == 'ZZZ' or nmaps[index][2] == 'ZZZ': + # print(nmaps[index][1],nmaps[index][2]) + # print('Found at ' + str(index) + ' with count ' + str(count)) + # found = True + # continue + # input() + print(count) + + diff --git a/2023/day8/test2 b/2023/day8/test2 new file mode 100644 index 0000000..7d1b58d --- /dev/null +++ b/2023/day8/test2 @@ -0,0 +1,5 @@ +LLR + +AAA = (BBB, BBB) +BBB = (AAA, ZZZ) +ZZZ = (ZZZ, ZZZ) diff --git a/2023/day8/test3 b/2023/day8/test3 new file mode 100644 index 0000000..38bd76a --- /dev/null +++ b/2023/day8/test3 @@ -0,0 +1,9 @@ +RLLRLRLRRLRLRLRLRL + +AAA = (BBB, CCC) +BBB = (DDD, EEE) +CCC = (ZZZ, GGG) +DDD = (DDD, DDD) +EEE = (EEE, EEE) +GGG = (GGG, GGG) +ZZZ = (ZZZ, ZZZ)