Last active
July 23, 2023 12:17
-
-
Save kiedtl/ca9f524487bc5b844525a6a97df9b0e6 to your computer and use it in GitHub Desktop.
Glory to the People's Republic. Glory to Dear Leader
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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