# anagram string (1 Viewer)

##### Newcomer
if i need to check if the array is anagram or if both array are anagram i just but each letter in a first array in hash with key that is the number of how much it in the index and check from the other array if the first index in the hash..

her i do'nt know from where to start cuz there is no hash map her so it make the solution difficult!
in my julia solution
this is the final code
Lua:
``````function anagrams(a,b)
res = zeros(Int,length(a))
for i=1:length(a)
a1 = sort(collect(a))
b1 = sort(collect(b))
for j=1:min(length(a1),length(b1))
if length(a1) <= length(b1)
if a1[j] in b1
res +=1
j +=1
else
j+=1
end
else
if b1[j] in a1
res +=1
j +=1
else
j+=1
end
end
end
end
return res
end

a = ["teewaa" , "ategh" , "simplefo"]
b = ["atwe" , "atcgh" , "fore"]

println(anagrams(a,b))``````

any one know how to convert it to lua ..

##### Newcomer
Lua:
``````function anagrams(a, b)
a1 = {}
for i = 1, #a do --3times
for j=1,#a do --3,3,8
t = string.sub(a,j,j) -- i try to do that,  but ,, how to complete
if -- ?
print(t)
end
end
end
end

a = {"tee" , "waa" ,"simplefo"}
b = {"atwe" , "atcgh" , "fore"}

print(anagrams(a,b))``````

#### dinsdale247

##### Moderator
Staff member
Community Patron
Creator of WinLua
Not sure what you're trying to do, but you can't use `string.sub` on "a" because it's a table. You can use `string.sub` on an element of "a":

Lua:
``````--I changed the name of your inputs
function anagrams(t1, t2)
a = t1 --turn this assignment into a loop...
for i = 1, #a do --3times
for j=1,#a do --3,3,8
t = string.sub(a,j,j)
print(t)
end
end
end

a = {"tee" , "waa" ,"simplefo"}
b = {"atwe" , "atcgh" , "fore"}

print(anagrams(a,b))``````