public class TextTwist {
private static final int ALPHABET = 256;
// return profile of ASCII string s
public static int[] profile(String s) {
int[] cnt = new int[ALPHABET];
for (int i = 0; i %26lt; s.length(); i++)
++cnt[s.charAt(i)];
return cnt;
}
// are two profiles identical?
public static boolean contains(int[] cnt1, int[] cnt2) {
for (int i = 0; i %26lt; ALPHABET; i++)
if (cnt1[i] %26lt; cnt2[i]) return false;
return true;
}
public static void main(String[] args) {
// comptue profile of input word
String word = args[0].toLowerCase();
int[] cnt1 = profile(word);
// read in dictionary words, one at a time and process
while (!StdIn.isEmpty()) {
String s = StdIn.readString().toLowerCase();
// check that s is of right length
if (s.length() %26lt; 4 || s.length() %26gt; word.length()) continue;
// compute profile of s
int[] cnt2 = profile(s);
// check against input word
if (contains(cnt1, cnt2)) System.out.println(s);
}
}
}Can anyone help me to convert this text twist java program into javascript? here's the code. thank you.?
If you're very familiar with Java, maybe you can consider using GWT to convert your Java
code to javascript.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment