Skip to content

Instantly share code, notes, and snippets.

@kiedtl
Last active July 23, 2023 12:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kiedtl/ca9f524487bc5b844525a6a97df9b0e6 to your computer and use it in GitHub Desktop.
Save kiedtl/ca9f524487bc5b844525a6a97df9b0e6 to your computer and use it in GitHub Desktop.
Glory to the People's Republic. Glory to Dear Leader
#!/usr/bin/env lua5.3
function shallow_copy(t)
local t2 = {}
for k,v in pairs(t) do
t2[k] = v
end
return t2
end
local enriched = 0
local depleted = 0
local array = {}
for i = 1,34 do
array[i] = 1
end
--array[03] = 99 * 4
array[03] = 99 * 12
for iter = 1,5000 do
local new = shallow_copy(array)
for i = 1,#array do
if array[i] >= 2 then
new[i] = new[i] - 2
if i == #array then
enriched = enriched + 1
else
new[i + 1] = new[i + 1] + 1
end
if i == 1 then
depleted = depleted + 1
else
new[i - 1] = new[i - 1] + 1
end
end
end
array = new
end
print("Dplt", depleted)
for i = 1,#array do
print(string.format("C %d:\t%d", i, array[i]))
end
print("Enrc", enriched)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment