# project-euler/122/euler-122.pl

+use List::MoreUtils qw(uniq);

+The most naive way of computing n15 requires fourteen multiplications:

+But using a "binary" method you can compute it in six multiplications:

+However it is yet possible to compute it in only five multiplications:

+We shall define m(k) to be the minimum number of multiplications to compute nk;

+For 1 ≤ k ≤ 200, find ∑ m(k).

+my @combinations = (undef, ['']);

+foreach my $n (2 .. 200)

+ foreach my $lower (1 .. ($n>>1))

+ my $upper = $n - $lower;

+ foreach my $l_set (@{$combinations[$lower]})

+ foreach my $u_set (@{$combinations[$upper]})

+ my $s = join(",", uniq(sort { $a <=> $b } (split(/,/,$l_set),split(/,/,$u_set), $n)));

+ $combinations[$n] = [sort { $a cmp $b } keys(%sets)];

+foreach my $n (2 .. 200)

+ $sum += min (map { scalar( my @x = split(/,/, $_)) } @{$combinations[15]});