2024 Dec 11th
This commit is contained in:
parent
08b4e30a3a
commit
f5a06a5a86
1 changed files with 30 additions and 0 deletions
30
Python/2024/11/main.py
Normal file
30
Python/2024/11/main.py
Normal file
|
|
@ -0,0 +1,30 @@
|
||||||
|
input = open("input", 'r').read().strip()
|
||||||
|
|
||||||
|
# d = [line for line in input]
|
||||||
|
# d = [[val for val in line.strip()] for line in input]
|
||||||
|
# d = {(complex(x,y)): int(c) for y,line in enumerate(input) for x,c in enumerate(line.strip())}
|
||||||
|
st = {int(s): 1 for s in input.split(" ")}
|
||||||
|
|
||||||
|
def blink(stone):
|
||||||
|
if stone == 0:
|
||||||
|
return [1]
|
||||||
|
strstone = str(stone)
|
||||||
|
ln = len(strstone)
|
||||||
|
if ln % 2 == 0:
|
||||||
|
return [int(strstone[ln//2:]), int(strstone[:ln//2])]
|
||||||
|
return [stone * 2024]
|
||||||
|
|
||||||
|
def run(stones, l=25):
|
||||||
|
for _ in range(l):
|
||||||
|
newstones = {}
|
||||||
|
for stone,total in stones.items():
|
||||||
|
for newstone in blink(stone):
|
||||||
|
if newstone in newstones:
|
||||||
|
newstones[newstone] += total
|
||||||
|
else:
|
||||||
|
newstones[newstone] = total
|
||||||
|
stones = newstones
|
||||||
|
return sum([ns for ns in stones.values()])
|
||||||
|
|
||||||
|
print(run(st))
|
||||||
|
print(run(st,75))
|
||||||
Loading…
Add table
Add a link
Reference in a new issue