Stern-Brocot sequence: Difference between revisions
Content added Content deleted
m (→{{header|Haskell}}: Applied Ormolu) |
SqrtNegInf (talk | contribs) m (→{{header|Raku}}: tidy) |
||
Line 4,232: | Line 4,232: | ||
(formerly Perl 6) |
(formerly Perl 6) |
||
{{works with|rakudo|2017-03}} |
{{works with|rakudo|2017-03}} |
||
<lang perl6>constant @Stern-Brocot = 1, 1, { |
<lang perl6>constant @Stern-Brocot = 1, 1, { |(@_[$_ - 1] + @_[$_], @_[$_]) given ++$ } ... *; |
||
|(@_[$_ - 1] + @_[$_], @_[$_]) given ++$ |
|||
} ... *; |
|||
put @Stern-Brocot[^15]; |
|||
for |
for flat 1..10, 100 -> $ix { |
||
"First occurrence of {$ix.fmt('%3d')} is at index: {(1+@Stern-Brocot.first($ix, :k)).fmt('%4d')}"; |
|||
} |
} |
||
Line 4,245: | Line 4,243: | ||
{{out}} |
{{out}} |
||
<pre>1 1 2 1 3 2 3 1 4 3 5 2 5 3 4 |
<pre>1 1 2 1 3 2 3 1 4 3 5 2 5 3 4 |
||
First occurrence of 1 is at index: 1 |
|||
First occurrence of 2 is at index: 3 |
|||
First occurrence of 3 is at index: 5 |
|||
First occurrence of 4 is at index: 9 |
|||
First occurrence of 5 is at index: 11 |
|||
First occurrence of 6 is at index: 33 |
|||
First occurrence of 7 is at index: 19 |
|||
First occurrence of 8 is at index: 21 |
|||
First occurrence of 9 is at index: 35 |
|||
First occurrence of 10 is at index: 39 |
|||
First occurrence of 100 is at index: 1179 |
|||
True</pre> |
True</pre> |
||