commit ca095f7

Artur Manuel  ·  2026-07-26 15:30:11 +0000 UTC
parent 5daa970
lua: add lua
1 files changed,  +26, -0
+26, -0
 1@@ -0,0 +1,26 @@
 2+local function collatz(n)
 3+  if n % 2 == 0 then
 4+    return math.floor(n / 2)
 5+  else
 6+    return 3 * n + 1
 7+  end
 8+end
 9+
10+local function collatzSequence(n)
11+  local buf = string.format("%d: ", n)
12+  local i = n
13+  while true do
14+    if i == 1 then
15+      buf = string.format("%s1", buf, i)
16+      break
17+    end
18+    buf = string.format("%s%d, ", buf, i)
19+    i = collatz(i)
20+  end
21+  return buf
22+end
23+
24+for i = 1,10000 do
25+  print(collatzSequence(i))
26+end
27+