Hey all!
Im pretty new to corona and especially Lua. I’m having some trouble with strings and how to execute different operations. I’m trying to make a function that checks two words to see if they are anagrams.
Here is what I have right now:
function main() local word1 = "rat" local word2 = "format" if (isAnagram(word1, word2) == true) then local myText = display.newText("They are anagrams", 30, 30, native.systemFont, 20) myText:setTextColor(0, 255, 0) else local myText = display.newText("They are not anagrams", 30, 30, native.systemFont, 20) myText:setTextColor(0, 255, 0) end end function isAnagram(first, second) counter = 0 for i = 0, string.len(first) do for j = 0, string.len(second) do if (string.byte(first, i) == string.byte(second, j)) then local myCharNum = string.byte(first, i) local myChar = string.char(myCharNum) string.gsub(first, myChar, "0", 1) counter = counter + 1 end end end if (counter \>= string.len(first)) then return true else return false end end main()
I don’t know what is quite wrong but I run this script and I get an error with the “local myChar = string.char(myCharNum)” line.
I’m not sure if this is a newbie question but could some one please help me with this. I would be very grateful.
Thanks!
-Tad