Hailstone sequence: Difference between revisions

m
→‎{{header|FutureBasic}}: Inserted code indents
m (syntax highlighting fixup automation)
m (→‎{{header|FutureBasic}}: Inserted code indents)
Line 4,559:
<syntaxhighlight lang="futurebasic">
local fn Hailstone( n as NSInteger ) as NSInteger
'~'1
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
'~'1
NSInteger count = 1, col = 1
print "Sequence for number "; n; ":" : print
 
print using "########"; n;
print "Sequence for number "; n; ":" : print
print using "########"; n;
col = 2
 
while ( n != 1 )
col = 2
while if ( n !=and 1 ) == 1
if ( n and 1 ) n == n * 3 + 1
n = n * 3 + 1count++
else
count++
n = n / 2
else
n = n / 2 count++
end if
count++
print using "########"; n;
end if
if col == 10 then print : col = 1 else col++
print using "########"; n;
wend
if col == 10 then print : col = 1 else col++
wend
print : print
 
print "Sequence length = "; count
print : print
print "Sequence length = "; count
end fn
 
Line 4,608 ⟶ 4,606:
 
for x = 1 to 100000
n = fn Hailstone( x )
if n > max_seq
max_x = x
max_seq = n
end if
next
 
Line 4,641 ⟶ 4,639:
The longest sequence is for 77031, it has a sequence length of 351.
</pre>
 
 
=={{header|Fōrmulæ}}==
408

edits