diff options
Diffstat (limited to 'challenge-100/stuart-little/lua/ch-1.lua')
| -rwxr-xr-x | challenge-100/stuart-little/lua/ch-1.lua | 16 |
1 files changed, 16 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)) |
