use 5.38.0; package Part2; use Part1; use List::AllUtils qw/ all sum /; sub predict(@entries) { my $sum = 0; until( all { !$_ } @entries ) { $sum = $entries[0]-$sum; @entries = map { $entries[$_]-$entries[$_-1] } 1..$#entries; } return -$sum; } sub solution_2 ($input) { my @lines = map { [split]} split "\n", $input; return sum map { predict(@$_) } @lines; } 1;