Data update
This commit is contained in:
parent
81fd053722
commit
52a6ef48dd
10248 changed files with 63654 additions and 6775 deletions
37
Task/Executable-library/FreeBASIC/executable-library-1.basic
Normal file
37
Task/Executable-library/FreeBASIC/executable-library-1.basic
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
Function hailstone(number As Uinteger) As Uinteger
|
||||
Dim As Uinteger count = 1
|
||||
|
||||
While number <> 1
|
||||
If (number And 1) = 1 Then
|
||||
number += number Shr 1 + 1
|
||||
count += 2
|
||||
Else
|
||||
number Shr= 1
|
||||
count += 1
|
||||
End If
|
||||
Wend
|
||||
Return count
|
||||
End Function
|
||||
|
||||
Sub Main()
|
||||
Dim As Uinteger seqlen
|
||||
seqlen = hailstone(27)
|
||||
Print "Sequence length for 27 is "; seqlen
|
||||
|
||||
Dim maxlen As uInteger = 0
|
||||
Dim maxnum As uInteger = 0
|
||||
For number As Uinteger = 2 To 100000
|
||||
seqlen = hailstone(number)
|
||||
If seqlen > maxlen Then
|
||||
maxlen = seqlen
|
||||
maxnum = number
|
||||
End If
|
||||
Next
|
||||
Print "The number with the longest hailstone sequence is "; maxnum
|
||||
Print "Its sequence length is "; maxlen
|
||||
Print
|
||||
End Sub
|
||||
|
||||
Main()
|
||||
|
||||
Sleep
|
||||
Loading…
Add table
Add a link
Reference in a new issue