Syracuse plotter


Root  Previous item  Next item

A small application that calculates and draws all visible values of a Syracuse sequence. Every natural, whole number has a value based on the Syracuse algorithm. This application draws a graph that shows this value as a dot. The Syracuse algorithm uses three rules of behaviour:

#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.


When we write this as a Visual Basic function then we get:

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



Download the zip-file archive which contains the complete VB6 source code or a compiled exe.
Exe_file_icon VB_file_icon


SyracuseScreenshot


 


For additional information.