diff options
Diffstat (limited to 'challenge-112')
| -rwxr-xr-x | challenge-112/stuart-little/lua/ch-1.lua | 28 | ||||
| -rwxr-xr-x | challenge-112/stuart-little/lua/ch-2.lua | 25 |
2 files changed, 53 insertions, 0 deletions
diff --git a/challenge-112/stuart-little/lua/ch-1.lua b/challenge-112/stuart-little/lua/ch-1.lua new file mode 100755 index 0000000000..6e4d951111 --- /dev/null +++ b/challenge-112/stuart-little/lua/ch-1.lua @@ -0,0 +1,28 @@ +#!/usr/bin/env lua + +-- run <script> <path> + +function deSlash(s) + local news = s:gsub("/+","/"):gsub("(.+)/$","%1") + return news +end + +function deDot(s) + local news = s:gsub("/%./","/"):gsub("/%.$","") + return news +end + +function deDblDotMid(s) + local news=s:gsub("/%.%.$","/../") + local fst = news:gmatch("([^/]*)/%.%./")() + if not fst then return news end + if fst == ".." or fst=="" then error("Too many double dots!") end + local sml = news:gsub(fst.."/%.%./","/",1) + return deDblDotMid(deSlash(sml)) +end + +function norm(s) + return deSlash(deDblDotMid(deDot(s))) +end + +print(norm(arg[1])) diff --git a/challenge-112/stuart-little/lua/ch-2.lua b/challenge-112/stuart-little/lua/ch-2.lua new file mode 100755 index 0000000000..2c5374463b --- /dev/null +++ b/challenge-112/stuart-little/lua/ch-2.lua @@ -0,0 +1,25 @@ +#!/usr/bin/env lua + +-- run <script> <number> + +local memo={[0]={{}},{{1}},{{1,1},{2}}} + +function pths(n) + if n >= #memo then + table.insert(memo,{}) + for i = 1,2 do + for _,pth in ipairs(memo[n-i]) do + table.insert(memo[n],table.pack(i,table.unpack(pth))) + end + end + end + return memo[n] +end + +for i = 3,arg[1] do + pths(i) +end + +for _,pth in ipairs(memo[tonumber(arg[1])]) do + print(table.unpack(pth)) +end |
