Executable library: Difference between revisions
Content added Content deleted
(Added Go) |
No edit summary |
||
Line 1,009: | Line 1,009: | ||
{{out}} |
{{out}} |
||
<pre>The most common hailstone length is 72.</pre> |
<pre>The most common hailstone length is 72.</pre> |
||
=={{header|Nanoquery}}== |
|||
The global boolean value 'main' is true is the program is being executed directly and false if it is being imported as a library. |
|||
<lang Nanoquery>def hailstone(n) |
|||
seq = list() |
|||
while (n > 1) |
|||
append seq n |
|||
if (n % 2)=0 |
|||
n = int(n / 2) |
|||
else |
|||
n = int((3 * n) + 1) |
|||
end |
|||
end |
|||
append seq n |
|||
return seq |
|||
end |
|||
if main |
|||
h = hailstone(27) |
|||
println "hailstone(27)" |
|||
println "total elements: " + len(hailstone(27)) |
|||
print h[0] + ", " + h[1] + ", " + h[2] + ", " + h[3] + ", ..., " |
|||
println h[-4] + ", " + h[-3] + ", " + h[-2] + ", " + h[-1] |
|||
max = 0 |
|||
maxLoc = 0 |
|||
for i in range(1,99999) |
|||
result = len(hailstone(i)) |
|||
if (result > max) |
|||
max = result |
|||
maxLoc = i |
|||
end |
|||
end |
|||
print "\nThe number less than 100,000 with the longest sequence is " |
|||
println maxLoc + " with a length of " + max |
|||
end</lang> |
|||
=={{header|NetRexx}}== |
=={{header|NetRexx}}== |