I take a look on the perl6 features, I think it is enough for me to do some euler problem.

I start at euler problem 52.

The problem is euler52

”

It can be seen that the number, 125874, and its double, 251748, contain exactly the same digits, but in a different order.

Find the smallest positive integer, x, such that 2x, 3x, 4x, 5x, and 6x, contain the same digits.”

sub digits_sort($num) { Str($num).comb.sort; } sub is_euler52($numb) { my @result=map {digits_sort($_) eqv digits_sort($numb)}, $numb<<*<<(2..6); [and] @result; } my $i=142850; repeat {$i++;} until is_euler52($i); say $i;

but it is two slow…

real | 0m1.689s |

user | 0m1.476s |

sys | 0m0.076s |

hope it will be better in the future..

#TODO: explain == eq eqv.

Advertisements