Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
18
Task/Hailstone-sequence/APL/hailstone-sequence-1.apl
Normal file
18
Task/Hailstone-sequence/APL/hailstone-sequence-1.apl
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
⍝ 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, and append the result of the recursive call
|
||||
}
|
||||
|
||||
⍝ tradfn version:
|
||||
∇seq←hailstone n;next
|
||||
⍝ Returns the hailstone sequence for a given number
|
||||
|
||||
seq←n ⍝ Init the sequence
|
||||
:While n≠1
|
||||
next←(n÷2) (1+3×n) ⍝ Compute both possibilities
|
||||
n←next[1+2|n] ⍝ Pick the appropriate next step
|
||||
seq,←n ⍝ Append that to the sequence
|
||||
:EndWhile
|
||||
∇
|
||||
10
Task/Hailstone-sequence/APL/hailstone-sequence-2.apl
Normal file
10
Task/Hailstone-sequence/APL/hailstone-sequence-2.apl
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
dfnHailstone 5
|
||||
5 16 8 4 2 1
|
||||
5↑hailstone 27
|
||||
27 82 41 124 62
|
||||
¯5↑hailstone 27
|
||||
16 8 4 2 1
|
||||
⍴hailstone 27
|
||||
112
|
||||
1↑{⍵[⍒↑(⍴∘hailstone)¨⍵]}⍳100000
|
||||
77031
|
||||
Loading…
Add table
Add a link
Reference in a new issue