38 lines
460 B
Plaintext
38 lines
460 B
Plaintext
function Hailstone(sys *n)
|
|
'=========================
|
|
if n and 1
|
|
n=n*3+1
|
|
else
|
|
n=n>>1
|
|
end if
|
|
end function
|
|
|
|
function HailstoneSequence(sys n) as sys
|
|
'=======================================
|
|
count=1
|
|
do
|
|
Hailstone n
|
|
Count++
|
|
if n=1 then exit do
|
|
end do
|
|
return count
|
|
end function
|
|
|
|
'MAIN
|
|
'====
|
|
|
|
maxc=0
|
|
maxn=0
|
|
e=100000
|
|
for n=1 to e
|
|
c=HailstoneSequence n
|
|
if c>maxc
|
|
maxc=c
|
|
maxn=n
|
|
end if
|
|
next
|
|
|
|
print e ", " maxn ", " maxc
|
|
|
|
'result 100000, 77031, 351
|