Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,32 @@
fun hailstone_step(x: int): int =
if (x % 2) == 0
then x/2
else (3*x) + 1
fun hailstone_seq(x: int): []int =
let capacity = 100
let i = 1
let steps = replicate capacity (-1)
let steps[0] = x
loop ((capacity,i,steps,x)) = while x != 1 do
let (steps, capacity) =
if i == capacity then
(concat steps (replicate capacity (-1)),
capacity * 2)
else (steps, capacity)
let x = hailstone_step x
let steps[i] = x
in (capacity, i+1, steps, x)
in #1 (split i steps)
fun hailstone_len(x: int): int =
let i = 1
loop ((i,x)) = while x != 1 do
(i+1, hailstone_step x)
in i
fun max (x: int) (y: int): int = if x < y then y else x
fun main (x: int) (n: int): ([]int, int) =
(hailstone_seq x,
reduce max 0 (map hailstone_len (map (1+) (iota (n-1)))))