Lychrel numbers: Difference between revisions

→‎{{header|Perl 6}}: rewrote to be much faster; O(n²) or maybe O(n logn) rather than O(n³)
m (→‎{{header|Perl 6}}: give some indication of progress)
(→‎{{header|Perl 6}}: rewrote to be much faster; O(n²) or maybe O(n logn) rather than O(n³))
Line 2,374:
 
=={{header|Perl 6}}==
{{works with|Rakudo|2015-10-102018.03}}
 
<lang perl6>my @%lychrels;
my @palindromes;
my @seeds;
my @palindromes;
my $count;
my $max = 500;
my $limit = 10_000;
 
for 1 .. 10000$limit -> $int {
my @test;
my $countindex = 0;
print "$int " and @lychrels.push( $int => [@test] ) if lychrel($int); {
print "\b" x 20, "Found Lychrel: $int";
%lychrels.push: ($int => [@test]).invert;
@palindromes.push: $l.keyint if $l.keyint == $l.keyint.flip;
$count++;
}
print "\b" x 20;
 
sub lychrel (Int $l) {
return True if $countindex++ > $max;
@test.push: my $m = $l + $l.flip;
return False if $m == $m.flip;
Line 2,394 ⟶ 2,402:
}
 
@seedsfor = @%lychrels{*}»[0];.unique.sort -> $ly {
my $next = False;
for @%lychrels -> $l {
@palindromes.push: $l.key if $l.key == $l.key.flip;
my for $triall.value[1..*] =-> $lt 0;{
$next = True and last if $ly == $lt;
for @seeds -> $s {
last if any($s.value)ly ~~< any($l.value)lt;
$trial++;}
last if $next;
}
@seeds.push: $lnext if $trial == +@seedsnext;
for @seeds ->.push: $s {ly;
}
 
say " Number of Lychrel seed numbers < 10_000$limit: ", +@seeds;
say " Lychrel seed numbers < 10_000$limit: ", join ", ", @seeds>>.keys;
say "Number of Lychrel related numbers < 10_000$limit: ", +@lychrels$count - @seeds;
say " Number of Lychrel palindromes < 10_000$limit: ", +@palindromes;
say " Lychrel palindromes < 10_000$limit: ", join ", ", @palindromes;</lang>
 
{{out}}
<pre> Number of Lychrel seed numbers < 10000: 5
<pre>
Number of Lychrel seed numbers < 10_00010000: 5196, 879, 1997, 7059, 9999
Number of Lychrel seedrelated numbers < 10_00010000: 196, 879, 1997, 7059, 9999244
Number of Lychrel related numberspalindromes < 10_00010000: 2443
Number of Lychrel palindromes < 10_00010000: 34994, 8778, 9999</pre>
Lychrel palindromes < 10_000: 4994, 8778, 9999
</pre>
 
=={{Header|PicoLisp}}==
10,327

edits