aboutsummaryrefslogtreecommitdiff
path: root/challenge-116/stuart-little/lua/ch-1.lua
blob: 810c543ce13a46763d3d8be96645be44bd2d585f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#!/usr/bin/env lua

-- run <script> <number>

function canSplit(lrg,sml)
   rest = lrg:match(sml .. "(.*)")
   if not rest then
      return nil
   end
   if lrg == sml then
      return lrg
   end
   nextIt = canSplit(rest,("%d"):format(sml+1))
   return nextIt and sml .. ", " .. nextIt or nil
end

for i=1,arg[1]:len() do
   res = canSplit(arg[1],arg[1]:sub(1,i))
   if res then
      print(res)
      os.exit()
   end
end