Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,48 @@
|
|||
Module hailstone.Task {
|
||||
hailstone=lambda (n as long)->{
|
||||
=lambda n (&val) ->{
|
||||
if n=1 then =false: exit
|
||||
=true
|
||||
if n mod 2=0 then n/=2 : val=n: exit
|
||||
n*=3 : n++: val=n
|
||||
}
|
||||
}
|
||||
Count=Lambda (n) ->{
|
||||
m=lambda n ->{
|
||||
if n=1 then =false: exit
|
||||
=true :if n mod 2=0 then n/=2 :exit
|
||||
n*=3 : n++
|
||||
}
|
||||
c=1
|
||||
While m() {c++}
|
||||
=c
|
||||
|
||||
}
|
||||
k=Hailstone(27)
|
||||
counter=1
|
||||
x=0
|
||||
Print 27,
|
||||
While k(&x) {
|
||||
counter++
|
||||
Print x,
|
||||
if counter=4 then exit
|
||||
}
|
||||
Print
|
||||
Flush ' empty current stack
|
||||
While k(&x) {
|
||||
counter++
|
||||
data x ' send to end of stack -used as FIFO
|
||||
if stack.size>4 then drop
|
||||
}
|
||||
\\ [] return a stack object and leave empty current stack
|
||||
\\ Print use automatic iterator to print all values in columns.
|
||||
Print []
|
||||
Print "counter:";counter
|
||||
m=0
|
||||
For i=2 to 99999 {
|
||||
m1=max.data(count(i), m)
|
||||
if m1<>m then m=m1: im=i
|
||||
}
|
||||
Print Format$("Number {0} has then longest hailstone sequence of length {1}", im, m)
|
||||
}
|
||||
hailstone.Task
|
||||
Loading…
Add table
Add a link
Reference in a new issue