|
Syracuse plotter
|
|
|
#1 If the number is an even value then divide the number by two.
#2 If the number is an odd value then multiply the number by three and add one. #3 If the number is one then the number of steps we took to get here is the Syracuse value of the original number. |
|
Public Function CalculateSyracuseValue(ByVal lngNumber As Long) As Long
Dim stepcount As Long Dim tmpValue As Long stepcount = 0 tmpValue = Abs(lngNumber) Do If tmpValue = 1 Then Exit Do 'rule #3 If IsNumberEven(valN) Then valN = valN / 2 'rule #1 Else valN = valN * 3 + 1 'rule #2 End If steps = steps + 1 Loop CalculateSyracuseValue = stepcount End Function |