generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: How to check if two Strings are anagrams of each other?

Previous Thread :: Next Thread 
OnlySinister is not online. OnlySinister
Joined: 07 Jan 2015
Total Posts: 885
09 Nov 2016 10:34 AM
^
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
09 Nov 2016 10:41 AM
one way would be to put the characters of the strings in abc order and check if their the same, def. more efficient than getting all permutations
Report Abuse
OnlySinister is not online. OnlySinister
Joined: 07 Jan 2015
Total Posts: 885
09 Nov 2016 10:42 AM
You're clever, I like it.
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
09 Nov 2016 10:44 AM
;) im magician
look

is this your card
Report Abuse
sayhisam1 is not online. sayhisam1
Joined: 25 Nov 2009
Total Posts: 2092
09 Nov 2016 11:31 AM
Another way is to start at each letter of the first string, go through the other string, check if letter is there, and then remove the letter from the array if it is.


Report Abuse
sayhisam1 is not online. sayhisam1
Joined: 25 Nov 2009
Total Posts: 2092
09 Nov 2016 11:35 AM
or just check the number of occurrences of each letter.



Report Abuse
AutoCarrot is not online. AutoCarrot
Joined: 24 Oct 2013
Total Posts: 5588
09 Nov 2016 11:39 AM
I really like ##### solution actually. It might be better to save you writing out ## ######### use string.byte and sort of size order ################ // Private Drive - Residents Only
Report Abuse
Wunder_Wulfe is online. Wunder_Wulfe
Joined: 13 Sep 2016
Total Posts: 8356
09 Nov 2016 11:53 AM
here u go

function anagram(s1,s2)
local matched = false
local string1=(s1):lower():gsub("%s+","")
local string2=(s2):lower():gsub("%s+","")
for i=1,#string1 do
local _,m1 = string2:gsub(string1:sub(i,i),"")
local _,m2 = string1:gsub(string1:sub(i,i),"")
matched=(m1==m2)
if not matched then break end
end
return matched
end

print(anagram("anagram","nag a ram"))
print(anagram("cool","no"))
Report Abuse
Wunder_Wulfe is online. Wunder_Wulfe
Joined: 13 Sep 2016
Total Posts: 8356
09 Nov 2016 11:56 AM
it just checks if the amount of each letter is consistent
Report Abuse
chimmihc is not online. chimmihc
Joined: 01 Sep 2014
Total Posts: 17143
09 Nov 2016 12:25 PM
pastebin /qKeQP95m


Report Abuse
Wunder_Wulfe is online. Wunder_Wulfe
Joined: 13 Sep 2016
Total Posts: 8356
09 Nov 2016 12:38 PM
lol yea i did too much
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image