about summary refs log tree commit diff
path: root/aoc/2021/07/part-two.raku
blob: d4934d91a85cf3ab74e609ff0f735254b54085f2 (plain) (blame)
1
2
3
4
my &cum = { $_ * ($_ + 1) div 2 };
my @input = map +*, split ',', trim slurp 'input';
sub cost($align) { [+] map { cum abs $align - $_ }, @input }
put min (cost $_ for (min @input)...(max @input))