1 Come up with a clear and interesting conjecture concerning
1. Come up with a clear and interesting conjecture concerning primes or the \"Hailstone\" Sequence.
2. Write a program that will allow the user (you!) to gather data regarding the conjecture posed in (1) Using Visual Basics.
Solution
\' please run this program in version VB6 Standard
Dim flag As Boolean \' true to print values
Sub main()
Dim longest As Long, n As Long
Dim i As Long, value As Long
Console.WriteLine(\"Enter some number :\")
i = Console.ReadLine() \' provide value for sequence
flag = True
Console.WriteLine(\"Sequence length of \" + i + \" is \" +hailstonesSequence(i))
flag = False
longest = 0
For i = 1 To 99999
If longest < hailstonesSequence(i) Then
longest = hailstonesSequence(i)
value = i
End If
Next i
Console.WriteLine(\" longest sequence \"+ longest)
End Sub
Function hailstonesSequence(n As Long) As Long
Dim a As Long, P As Long
Dim a1 As Long, a2 As Long, a3 As Long, a4 As Long
If flag Then Console.WriteLine(\"The sequence \"+ n +\"is \")
P = 1
a = n
If flag Then Console.WriteLine(a)
While a > 1
P = P + 1
If (a Mod 2) = 0 Then
a = a / 2
Else
a = 3 * a + 1
End If
If P <= 4 Then If flag Then Console.WriteLine(a)
a4 = a3
a3 = a2
a2 = a1
a1 = a
Wend
If flag Then
If P <= 4 Then
Console.WriteLine()
ElseIf P = 5 Then
Console.WriteLine(a1)
ElseIf P = 6 Then
Console.WriteLine(a2+\" \"+a1)
ElseIf P = 7 Then
Console.WriteLine(a3+\" \"+a2 +\" \"+a1)
ElseIf P = 8 Then
Console.WriteLine(a4+\" \"+a3\" \"+a2\"\" +a1)
Else
Console.WriteLine(\"...\"+ a4 +\" \" +a3 +\" \" +a2 +\" \" +a1)
End If
End If
hailstonesSequence = PEnd Function
-----Sample output--------------------------------
27, 82, 41, 124, ....., 8,4,2,1
Sequence length of 7 is 114

