Find palindromic numbers in both binary and ternary bases: Difference between revisions

Content deleted Content added
Trizen (talk | contribs)
Added Sidef
Thundergnat (talk | contribs)
→‎{{header|Perl 6}}: GLR updates. Remove apology for speed. (runs in about 1/40th the time as when originally posted.)
Line 320:
 
=={{header|Perl 6}}==
Instead of searching for numbers that are palindromes in one base then checking the other, generate palindromic trinary numbers directly, then check to see if they are also binary palindromes (with additional simplifying constraints as noted in other entries). Outputs the list in decimal, binary and trinary. Getting the 6th number requires about 4 cpu minutes on an i7.
 
<lang perl6>constant palindromes = 0, 1, |gather for 1 .. * -> $p {
my $pal = $p.base(3);
my $n = :3($pal ~ '1' ~ $pal.flip);