最大回文数积
作者:David Romano
https://projecteuler.net/problem=4
回文数是指正序(从左到右)和倒序(从右到左)读起来都一样的数字。由两个两位数相乘得到的最大回文数是 9009 = 91 × 99。
求由两个三位数相乘得到的最大回文数。
源代码:prob004-unobe.pl
use v6;
# another case where @array = %*% (100..999) would be nice to have:
# http://use.perl.org/~dpuu/journal/38142
sub diagonal_x (@array is copy) {
gather while @array.shift -> $this {
for @array -> $that { take $this * $that }
}
}
diagonal_x(100...999).grep({ $_ eq $_.flip }).sort.reverse.[0].say;
Perl 6 示例