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

-- run <script> <space-separated strings>

function oneWay(s1,s2)
   local t={}
   for i=1,s1:len() do
      if i>s2:len() then return false end
      if not t[s1:sub(i,i)] then t[s1:sub(i,i)] = s2:sub(i,i) end
   end
   return s2 == s1:gsub(".",t)
end

print(oneWay(arg[1],arg[2]) and oneWay(arg[2],arg[1]) and 1 or 0)