sub solve(@n --> List:D) {
my @m = @n;
my @N = @m.deepmap(*.clone),;
while +@m.unique > 1 {
my @m_ = (^(+@m-1)).map({ @m[$_+1] - @m[$_] });
@N.push(@m_.item);
@m = @m_;
}
for +@N-2 ... 0 -> $i {
@N[$i].push( @N[$i].tail + @N[$i+1].tail);
@N[$i].unshift(@N[$i].head - @N[$i+1].head);
}
@N[0].tail, @N[0].head
}
with [«+»] $*IN.lines.map({ solve(.words) }) {
put 'part 1: ', .[0];
put 'part 2: ', .[1];
}