RosettaCodeData/Task/Stern-Brocot-sequence/Perl-6/stern-brocot-sequence.pl6

12 lines
301 B
Raku
Raw Permalink Normal View History

2017-09-23 10:01:46 +02:00
constant @Stern-Brocot = 1, 1, {
|(@_[$_ - 1] + @_[$_], @_[$_]) given ++$
} ... *;
 
say @Stern-Brocot[^15];
 
for (flat 1..10, 100) -> $ix {
say "first occurrence of $ix is at index : ", 1 + @Stern-Brocot.first($ix, :k);
2015-02-20 09:02:09 -05:00
}
2017-09-23 10:01:46 +02:00
 
say so 1 == all map ^1000: { [gcd] @Stern-Brocot[$_, $_ + 1] }