aboutsummaryrefslogtreecommitdiff
path: root/challenge-082/stuart-little/lua/ch-2.lua
blob: 07b1a448f6e82ec691b16e4b8b0ccbc454e86a2c (plain)
1
2
3
4
5
6
7
8
9
10
11
#!/usr/bin/env lua

-- run <script> <space-separated strings, with the target string last>

function canInterleave(a,b,c)
   if math.max(a:len(),b:len(),c:len()) == 0 then return true end
   if a:sub(1,1) == c:sub(1,1) then return canInterleave(a:sub(2),b,c:sub(2)) end
   if b:sub(1,1) == c:sub(1,1) then return canInterleave(a,b:sub(2),c:sub(2)) end
   return false
end
print(canInterleave(table.unpack(arg,1,3)) and 1 or 0)