Data update
This commit is contained in:
parent
35bcdeebf8
commit
74c69a0df6
2427 changed files with 31826 additions and 3468 deletions
24
Task/Hailstone-sequence/SETL/hailstone-sequence.setl
Normal file
24
Task/Hailstone-sequence/SETL/hailstone-sequence.setl
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
program hailstone_sequence;
|
||||
hail27 := hailstone(27);
|
||||
print("The hailstone sequence for the number 27 has", #hail27, "elements,");
|
||||
print("starting with", hail27(..4), "and ending with", hail27(#hail27-3..));
|
||||
|
||||
sizes := [#hailstone(n) : n in [1..99999]];
|
||||
maxsize := max/sizes;
|
||||
maxelem := [n : n in [1..#sizes] | sizes(n) = maxsize](1);
|
||||
|
||||
print("The number < 100,000 with the longest hailstone sequence is",maxelem);
|
||||
print("The length of its sequence is",sizes(maxelem));
|
||||
|
||||
proc hailstone(n);
|
||||
seq := [];
|
||||
loop doing seq with:= n; while n/=1 do
|
||||
if even n then
|
||||
n div:= 2;
|
||||
else
|
||||
n := 3*n + 1;
|
||||
end if;
|
||||
end loop;
|
||||
return seq;
|
||||
end proc;
|
||||
end program;
|
||||
Loading…
Add table
Add a link
Reference in a new issue