Started 2017/24 part 1

This commit is contained in:
FrederikBaerentsen 2024-11-30 20:13:48 +01:00
parent 0e83d8f589
commit fcd169e923
4 changed files with 31 additions and 2 deletions

View File

@ -2,11 +2,12 @@
import sys,re import sys,re
from pprint import pprint from pprint import pprint
sys.path.insert(0, '../../') sys.path.insert(0, '../../')
from fred import list2int from fred import list2int, lprint,get_re
input_f = 'test' input_f = 'test'
part = 1 part = 1
log = True
######################################### #########################################
# # # #
# Part 1 # # Part 1 #
@ -14,8 +15,32 @@ part = 1
######################################### #########################################
if part == 1: if part == 1:
components = []
with open(input_f) as file: with open(input_f) as file:
for line in file: for line in file:
components.append(line.rstrip())
lprint(components,log)
pairs = []
for i in components:
t = []
i_match = get_re(r"^(\d+)\/(\d+)$",i)
if i_match.group(1) == '0': #can start
pairs.append([i])
for j in (components):
j_match = get_re(r"^(\d+)\/(\d+)$",j)
if i_match.group(2) == j_match.group(1) or i_match.group(2) == j_match.group(2):
#if i[2] == j[0] or i[2] == j[2]:
t.append(j)
pairs.append(t)
lprint(t,log)
input()
lprint(pairs,log)

View File

@ -95,7 +95,7 @@
## 2015 ## 2015
>@>o<O>>O<<<O>>>*>>*<*>>*<O<<o<<<O>>@<< 6 ** >@>o<O>>O<<<O>>>*>>*<*>>*<O<<o<<<O>>@<< 6 **
>@<@<O>>>o<<O>>O<O>@>@>>>@>>o<*<<<*<<<@<< 5 * >@<@<O>>>o<<O>>O<O>@>@>>>@>>o<*<<<*<<<@<< 5 **
>*>>O>@>>>@>>@>>>o<<<*<<<@>>@<<O<<<@<<O<<<< 4 ** >*>>O>@>>>@>>@>>>o<<<*<<<@>>@<<O<<<@<<O<<<< 4 **
>>o<o<<o>>O<@>>o<o>o<<<o>>*<<<O<*>>O<<<O>>o<< 3 ** >>o<o<<o>>O<@>>o<o>o<<<o>>*<<<O<*>>O<<<O>>o<< 3 **
>>O<<o<@<<<O<@>>>o>>@<o>o>*<<<o>@>>*>o<<<@<o<<< 2 ** >>O<<o<@<<<O<@>>>o>>@<o>o>*<<<o>@>>*>o<<<@<o<<< 2 **

Binary file not shown.

View File

@ -12,6 +12,10 @@ def toGrid(input,parser=None):
grid.append(list(line.rstrip())) grid.append(list(line.rstrip()))
return grid return grid
def lprint(x:str,log:bool):
if log:
print(x)
def expand_grid(grid): def expand_grid(grid):
num_rows = len(grid) num_rows = len(grid)
num_cols = len(grid[0]) num_cols = len(grid[0])