Code: Alles auswählen
f=lambda n:n-1and[n]+f((n//2,3*n+1)[n%2])or[1]
Code: Alles auswählen
f=lambda n:n-1and[n]+f((n//2,3*n+1)[n%2])or[1]
Code: Alles auswählen
Λ=lambda n:3*n+1
V=lambda n:n//2
def collatz(n):
l=[n]
while n!=1:l+=[n:=[V,Λ][n%2](n)]
return l
Code: Alles auswählen
from itertools import*;*a,o=open(0);s=str.split;b=map("".join,zip(*a));o=[o.join for o in s(o)]
print(sum(eval(o(a))for o,*a in zip(o,*map(s,a))),sum(eval(o(takewhile(str.strip,b)))for o in o))
Da kann man noch ein bisschen was rausholen. Zum Beispiel hiermit.https://adventofcode.com/2024/about hat geschrieben: Nor do you need a fancy computer; every problem has a solution that completes in at most 15 seconds on ten-year-old hardware.
Doch, du bekommst eine Fehlermeldung. Du ignorierst sie nur explizit.