diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2021-07-15 21:02:03 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-07-15 21:02:03 +0100 |
| commit | 81031de3c1d8fe1c389a60f1c4514e17b4989ea7 (patch) | |
| tree | 2bc6455857f345a77c4ce4c03314684258947989 | |
| parent | 3cf2f377eb630f019d81293e81885a8a3a1ba187 (diff) | |
| parent | 81465123f99e4ef5f088a4fb8fab6678723c8d49 (diff) | |
| download | perlweeklychallenge-club-81031de3c1d8fe1c389a60f1c4514e17b4989ea7.tar.gz perlweeklychallenge-club-81031de3c1d8fe1c389a60f1c4514e17b4989ea7.tar.bz2 perlweeklychallenge-club-81031de3c1d8fe1c389a60f1c4514e17b4989ea7.zip | |
Merge pull request #4526 from stuart-little/stuart-little_100_lua
1st commit on 100_lua
| -rwxr-xr-x | challenge-100/stuart-little/lua/ch-1.lua | 16 | ||||
| -rwxr-xr-x | challenge-100/stuart-little/lua/ch-2.lua | 39 |
2 files changed, 55 insertions, 0 deletions
diff --git a/challenge-100/stuart-little/lua/ch-1.lua b/challenge-100/stuart-little/lua/ch-1.lua new file mode 100755 index 0000000000..29f1bc624f --- /dev/null +++ b/challenge-100/stuart-little/lua/ch-1.lua @@ -0,0 +1,16 @@ +#!/usr/bin/env lua + +-- run <script> <time, formatted as hh:mm [am/pm]> + +function cvrt(h,m,ap) + if ap:len() > 0 then + local hap = (ap:lower()=="am") and (("%02d"):format(tonumber(h)%12)) or (("%02d"):format(12+(tonumber(h)%12))) + return hap..":"..("%02d"):format(m) + end + ap=(tonumber(h)>=12) and " pm" or " am" + h=((tonumber(h)>12) and h-12) or (tonumber(h)==0 and 12) or h + return ("%02d"):format(h)..":"..("%02d"):format(m)..ap +end + +local h,m,ap=table.concat(arg,""):match("(%d+):(%d+)%s*([a-zA-Z]*)") +print(cvrt(h,m,ap)) diff --git a/challenge-100/stuart-little/lua/ch-2.lua b/challenge-100/stuart-little/lua/ch-2.lua new file mode 100755 index 0000000000..0f47095561 --- /dev/null +++ b/challenge-100/stuart-little/lua/ch-2.lua @@ -0,0 +1,39 @@ +#!/usr/bin/env lua + +--[[ +run <script> <file containing triangle> + +for instance, copy + + 1 + 2 4 + 6 4 9 + 5 1 7 2 + +to a text file and pass that file's path +--]] + +function clps(state,row) + local newS={} + for k,v in ipairs(row) do + local val=v+((state[k] and state[k-1] and math.min(tonumber(state[k]),tonumber(state[k-1]))) or state[k] or state[k-1] or 0) + table.insert(newS,val) + end + return newS +end + +local state={} +local tr={} +for l in io.lines(arg[1]) do + if l:find("%d") then + local row={} + for num in l:gmatch("-?%d+") do table.insert(row,num) end + table.insert(tr,row) + end +end + +for _,v in ipairs(tr) do + state=clps(state,v) +end + +print((#state > 0) and math.min(table.unpack(state)) or 0) |
