aoc

My solutions for the Advent of Code
git clone https://git.tronto.net/aoc
Download | Log | Files | Refs | README

b.py (342B)


      1 import fileinput
      2 from functools import cache
      3 
      4 neginf = -1e13
      5 
      6 @cache
      7 def joltage(line, n):
      8 	if n == 0:
      9 		return 0
     10 	if n > len(line)-1:
     11 		return neginf
     12 	j = 0
     13 	for i in range(len(line)-1):
     14 		j = max(j, int(line[i])*10**(n-1)+joltage(line[i+1:],n-1))
     15 	return j
     16 
     17 with fileinput.input() as lines:
     18 	print(sum(joltage(line, 12) for line in lines))