Hailstone sequence: Difference between revisions

Line 771:
=={{header|APL}}==
{{works with|Dyalog APL}}
<lang APL>seq←hailstone n;next
⍝ recursive dfn:
dfnHailstone←{
c←⊃⌽⍵ ⍝ last element
1=c:1 ⍝ if it is 1, stop.
⍵,∇(1+2|c)⊃(c÷2)(1+3×c) ⍝ otherwise pick the next step
}
 
⍝ tradfn version:
∇seq←hailstone n;next
⍝ Returns the hailstone sequence for a given number
 
Line 779 ⟶ 788:
n←next[1+2|n] ⍝ Pick the appropriate next step
seq,←n ⍝ Append that to the sequence
:EndWhile</lang>
 
</lang>
{{out}}
<lang APL> 5↑hailstonedfnHailstone 275
5 16 8 4 2 1
5↑hailstone 27
27 82 41 124 62
¯5↑hailstone 27
236

edits