Stern-Brocot sequence: Difference between revisions
Add APL
Not a robot (talk | contribs) (Add BASIC) |
Not a robot (talk | contribs) (Add APL) |
||
Line 519:
First 9 at 35; First 10 at 39; First 100 at 1179.
Correct: The first 999 consecutive pairs are relative prime!</pre>
=={{header|APL}}==
<lang APL>task←{
stern←{⍵{
⍺←0 ⋄ ⍺⍺≤⍴⍵:⍺⍺↑⍵
(⍺+1)∇⍵,(+/,2⊃⊣)2↑⍺↓⍵
}1 1}
seq←stern 1200 ⍝ Cache 1200 elements
⎕←'First 15 elements:',15↑seq
⎕←'Locations of 1..10:',seq⍳⍳10
⎕←'Location of 100:',seq⍳100
⎕←'All GCDs 1:','no' 'yes'[1+1∧.=2∨/1000↑seq]
}</lang>
{{out}}
<pre>First 15 elements: 1 1 2 1 3 2 3 1 4 3 5 2 5 3 4
Locations of 1..10: 1 3 5 9 11 33 19 21 35 39
Location of 100: 1179
All GCDs 1: yes </pre>
=={{header|AppleScript}}==
|