primo
16-08-2018, 09:09
Choose any positive integer and call it N.
If the number is odd, triple it and add 1, or in other words replace N by 3N + 1.
If the number is even, divide it by 2, replacing N by N /2
continue this procedure until the result converge to 1
the problem is that no one is able to device an algorithm to know how much steps needs to converge to 1. no general solution has been devised.
https://www.math.hmc.edu/funfacts/ffiles/10008.5.shtml
http://mathworld.wolfram.com/HailstoneNumber.html
look article from 1984
http://s000.tinyupload.com/index.php?file_id=24405899852244428304
Uses "Console"
String s, a
Long n
Long i, test
For test = 1 To 10000
n = 0: i = 0
PrintL "write the number under investigation "
s = Console_ReadLine()
n = Val(s)
If n = 0 Then Exit For
For i=1 To 1000000
If Mod(n,2)=0 Then
n=n/2
Else
n=n*3+1
EndIf
Print Str$(n) + " "
If n=1 Then Exit For
Next
PrintL
Print "number of iterations = " +Str$(i)
PrintL
PrintL " Press q to end program any other key to continue testing"
s = Console_ReadLine()
If s = "q" Then Exit For
Next
If the number is odd, triple it and add 1, or in other words replace N by 3N + 1.
If the number is even, divide it by 2, replacing N by N /2
continue this procedure until the result converge to 1
the problem is that no one is able to device an algorithm to know how much steps needs to converge to 1. no general solution has been devised.
https://www.math.hmc.edu/funfacts/ffiles/10008.5.shtml
http://mathworld.wolfram.com/HailstoneNumber.html
look article from 1984
http://s000.tinyupload.com/index.php?file_id=24405899852244428304
Uses "Console"
String s, a
Long n
Long i, test
For test = 1 To 10000
n = 0: i = 0
PrintL "write the number under investigation "
s = Console_ReadLine()
n = Val(s)
If n = 0 Then Exit For
For i=1 To 1000000
If Mod(n,2)=0 Then
n=n/2
Else
n=n*3+1
EndIf
Print Str$(n) + " "
If n=1 Then Exit For
Next
PrintL
Print "number of iterations = " +Str$(i)
PrintL
PrintL " Press q to end program any other key to continue testing"
s = Console_ReadLine()
If s = "q" Then Exit For
Next