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,7 @@
procedure hailstone(n)
while n > 1 do {
suspend n
n := if n%2 = 0 then n/2 else 3*n+1
}
suspend 1
end

View file

@ -0,0 +1,4 @@
procedure main(args)
n := integer(!args) | 27
every writes(" ",hailstone(n))
end

View file

@ -0,0 +1,9 @@
procedure hailstone(n)
static cache
initial {
cache := table()
cache[1] := [1]
}
/cache[n] := [n] ||| hailstone(if n%2 = 0 then n/2 else 3*n+1)
return cache[n]
end

View file

@ -0,0 +1,23 @@
procedure main(args)
n := integer(!args) | 27
task2(n)
write()
task3()
end
procedure task2(n)
count := 0
every writes(" ",right(!(sequence := hailstone(n)),5)) do
if (count +:= 1) % 15 = 0 then write()
write()
write(*sequence," value",(*sequence=1,"")|"s"," in the sequence.")
end
procedure task3()
maxHS := 0
every n := 1 to 100000 do {
count := *hailstone(n)
if maxHS <:= count then maxN := n
}
write(maxN," has a sequence of ",maxHS," values")
end