Hi All
The dark cold nights are here so skipping around youtube increases found a video on the Collatz
conjecture, and thought seems a nice little exercise for the picaxe
The dark cold nights are here so skipping around youtube increases found a video on the Collatz
conjecture, and thought seems a nice little exercise for the picaxe
Code:
'The Collatz conjecture in mathematics asks whether repeating certain simple arithmetic operations will eventually transform every positive integer into one
' If the number is even, divide it by two.
' If the number is odd, triple it and add one.
symbol steps=w5
symbol n=w0
symbol value=w6
main:
n=12
sertxd("value of n= ",#n,",")
do
steps=steps+1
if n=1 then
gosub fin
elseif bit0=0 then gosub divide 'bit0 dictates if odd or even
elseif bit0=1 then gosub tripple
endif
sertxd(#n,",")
loop
divide:'bit0 is even so divide by 2
n=n/2
value=value+1'for resetting n start value
return
tripple:'bit0 is odd tripple it and add 1
n=n*3
n=n+1
value=value+1
return
fin: sertxd(cr,lf)
sertxd("number of steps before n1= ",#steps,cr,lf)
sertxd("next value for n= ",#value,cr,lf)
n=value
steps=0
sertxd("value of n= ")
return
[/code}
love the fact that every string ends in 5,16,8,4,2,1 irrespective of the starting value for n
regards john