Skip to content

Instantly share code, notes, and snippets.

@ionox0
Created May 6, 2015 02:06
Show Gist options
  • Save ionox0/61d00fe34c2d6c25e413 to your computer and use it in GitHub Desktop.
Save ionox0/61d00fe34c2d6c25e413 to your computer and use it in GitHub Desktop.
Are two words anagrams? (you get what i mean...)
class MyClass {
public static void check_anagrams(String[] firstWords, String[] secondWords) {
String characters = "abcdefghijklmnopqrstuvwxyz";
int[] primes = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101};
for (int i = 0; i < firstWords.length; i++){
char a;
char b;
int firstWordValue = 1;
int secondWordValue = 1;
for (int j = 0; j < firstWords[i].length(); j++){
if (j >= secondWords[i].length()) break;
a = firstWords[i].charAt(j);
b = secondWords[i].charAt(j);
firstWordValue *= primes[characters.indexOf(a)];
secondWordValue *= primes[characters.indexOf(b)];
}
if (firstWordValue == secondWordValue){
System.out.println(1);
} else {
System.out.println(0);
}
}
}
}
long
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment