Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
35
Task/Hailstone-sequence/MLite/hailstone-sequence.mlite
Normal file
35
Task/Hailstone-sequence/MLite/hailstone-sequence.mlite
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
fun hail (x = 1) = [1]
|
||||
| (x rem 2 = 0) = x :: hail (x div 2)
|
||||
| x = x :: hail (x * 3 + 1)
|
||||
|
||||
fun hailstorm
|
||||
([], i, largest, largest_at) = (largest_at, largest)
|
||||
| (x :: xs, i, largest, largest_at) =
|
||||
let
|
||||
val k = len (hail x)
|
||||
in
|
||||
if k > largest then
|
||||
hailstorm (xs, i + 1, k, i)
|
||||
else
|
||||
hailstorm (xs, i + 1, largest, largest_at)
|
||||
end
|
||||
| (x :: xs) = hailstorm (x :: xs, 1, 0, 0)
|
||||
|
||||
;
|
||||
|
||||
val h27 = hail 27;
|
||||
print "hailstone sequence for the number 27 has ";
|
||||
print ` len (h27);
|
||||
print " elements starting with ";
|
||||
print ` sub (h27, 0, 4);
|
||||
print " and ending with ";
|
||||
print ` sub (h27, len(h27)-4, len h27);
|
||||
println ".";
|
||||
|
||||
val biggest = hailstorm ` iota (100000 - 1);
|
||||
|
||||
print "The number less than 100,000 which has the longest ";
|
||||
print "hailstone sequence is at element ";
|
||||
print ` ref (biggest, 0);
|
||||
print " and is of length ";
|
||||
println ` ref (biggest, 1);
|
||||
Loading…
Add table
Add a link
Reference in a new issue