File tree Expand file tree Collapse file tree 1 file changed +9
-9
lines changed
Expand file tree Collapse file tree 1 file changed +9
-9
lines changed Original file line number Diff line number Diff line change @@ -19,13 +19,13 @@ def part_1(input: Path) -> int:
1919def part_2 (input : Path ) -> int :
2020 total_joltage = 0
2121 for bank in input .read_text ().splitlines ():
22- joltages = [ 0 ] * 12
23- for idx , joltage in enumerate ( bank ):
24- joltage = int ( joltage )
25- for idx2 in range ( 12 ):
26- if idx <= len ( bank ) - ( 12 - idx2 ) and joltage > joltages [ idx2 ]:
27- joltages [ idx2 ] = joltage
28- joltages [ idx2 + 1 :] = [ 0 ] * ( 12 - ( idx2 + 1 ))
29- break
30- total_joltage += int ("" . join ( str ( j ) for j in joltages ) )
22+ bank_joltages : str = ""
23+ window_start_idx , window_end_idx = 0 , - 11
24+ for _ in range ( 12 ):
25+ window = bank [ window_start_idx : ( window_end_idx or None )]
26+ window_max_joltage = max ( window )
27+ bank_joltages += window_max_joltage
28+ window_start_idx += window . index ( window_max_joltage ) + 1
29+ window_end_idx += 1
30+ total_joltage += int (bank_joltages )
3131 return total_joltage
You can’t perform that action at this time.
0 commit comments