diff options
| author | Dave Jacoby <jacoby.david@gmail.com> | 2021-07-12 10:48:31 -0400 |
|---|---|---|
| committer | Dave Jacoby <jacoby.david@gmail.com> | 2021-07-12 10:48:31 -0400 |
| commit | 34a6514808c066bee4e7f3d7d8bdeb67db056392 (patch) | |
| tree | 05d0e268045ef3d6f971ec0e0c3eb1a48bdb7edd /challenge-112 | |
| parent | b59f8f4008bb8ec491a9e89f097f04ce54aed4c0 (diff) | |
| parent | 1aa7b6eaba2a58fc1ef0612373e3aed6b61f345d (diff) | |
| download | perlweeklychallenge-club-34a6514808c066bee4e7f3d7d8bdeb67db056392.tar.gz perlweeklychallenge-club-34a6514808c066bee4e7f3d7d8bdeb67db056392.tar.bz2 perlweeklychallenge-club-34a6514808c066bee4e7f3d7d8bdeb67db056392.zip | |
Merge branch 'master' of https://github.com/manwar/perlweeklychallenge-club
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 |
