Crypt analysis
http://www.careercup.com/question?id=5116391780777984
class EvelExpression implements Expression {
String input1, input2, result;
Set<Character> chars;
public EvelExpression(String s1, String s2, String result) {
input1 = s1;
input2 = s2;
this.result = result;
chars = new HashSet<>();
}
private void addCharacter(Set<Character> chars, String s) {
for (int pos = 0; pos < s.length(); pos++) {. more info on 1point3acres.com
chars.add(s.charAt(pos));
}
}
Set<Character> getChars() {. 1point3acres.com/bbs
addCharacter(chars, s1);
addCharacter(chars, s2);
addCharacter(chars, result);
return chars;
}
private int getNum(String s, Map<Character, Integer> proposedSolution) {
int res = 0;
for (int pos = 0; pos < s.length()(); pos++) {
res = res * 10 + proposedSolution.get(s.charAt(pos));
}
return res;
}
boolean eval(Map<Character, Integer> proposedSolution) {
int num1 = getNum(input1, proposedSolution), num2 = getNum(input2, proposedSolution);
int res = getNum(result, proposedSolution);
return res == (num1 + num2);
}
}