Created
December 6, 2025 14:57
-
-
Save jul/a56ff33bb47937d63dca44bfd52cc349 to your computer and use it in GitHub Desktop.
advent6
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| input="""123 328 51 64 | |
| 45 64 387 23 | |
| 6 98 215 314 | |
| * + * +""" | |
| import re | |
| from functools import reduce | |
| all= input.split("\n") | |
| X = len(all) | |
| Y=len(re.split(r"\s+", all[0].strip())) | |
| Z=0 | |
| for line in all: | |
| for col in re.split(r"\s+",line): | |
| Z=max(Z, len(col)) | |
| stack=[ ["",] * X for x in range(Y) ] | |
| print(stack) | |
| for x,l in enumerate(reversed(all)): | |
| for y,col in enumerate(re.split(r'\s+',l.strip())[::-1]): | |
| if col in {"*", "+" }: | |
| stack[y][-1]=col | |
| else: | |
| col = l[y*(X):min(y*(X)+(X-1), len(l))] | |
| col=col.replace(" ", "0") | |
| for index,digit in enumerate(col): | |
| stack[y][index] = digit + stack[y][index] | |
| total=0 | |
| print(stack) | |
| for l in stack: | |
| print(list(map(lambda s:s.strip("0"),l))) | |
| total += reduce([int.__mul__, int.__add__][l[-1] == '*'],map(lambda s:int(s.strip("0") or "0") , l[0:-1])) | |
| print( total) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment