Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
59
Task/Hailstone-sequence/FutureBasic/hailstone-sequence.basic
Normal file
59
Task/Hailstone-sequence/FutureBasic/hailstone-sequence.basic
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
local fn Hailstone( n as NSInteger ) as NSInteger
|
||||
NSInteger count = 1
|
||||
|
||||
while ( n != 1 )
|
||||
if ( n and 1 ) == 1
|
||||
n = n * 3 + 1
|
||||
count++
|
||||
end if
|
||||
n = n / 2
|
||||
count++
|
||||
wend
|
||||
end fn = count
|
||||
|
||||
|
||||
|
||||
void local fn PrintHailstone( n as NSInteger )
|
||||
NSInteger count = 1, col = 1
|
||||
|
||||
print "Sequence for number "; n; ":" : print
|
||||
print using "########"; n;
|
||||
|
||||
col = 2
|
||||
while ( n != 1 )
|
||||
if ( n and 1 ) == 1
|
||||
n = n * 3 + 1
|
||||
count++
|
||||
else
|
||||
n = n / 2
|
||||
count++
|
||||
end if
|
||||
print using "########"; n;
|
||||
if col == 10 then print : col = 1 else col++
|
||||
wend
|
||||
|
||||
print : print
|
||||
print "Sequence length = "; count
|
||||
end fn
|
||||
|
||||
window 1, @"Hailstone Sequence", ( 0, 0, 620, 400 )
|
||||
|
||||
NSInteger n, seq_num, x, max_x, max_seq
|
||||
|
||||
seq_num = 27
|
||||
|
||||
print
|
||||
fn PrintHailstone( seq_num )
|
||||
print
|
||||
|
||||
for x = 1 to 100000
|
||||
n = fn Hailstone( x )
|
||||
if n > max_seq
|
||||
max_x = x
|
||||
max_seq = n
|
||||
end if
|
||||
next
|
||||
|
||||
print "The longest sequence is for "; max_x; ", it has a sequence length of "; max_seq; "."
|
||||
|
||||
HandleEvents
|
||||
Loading…
Add table
Add a link
Reference in a new issue