Last active
December 19, 2015 02:39
-
-
Save exoego/5884390 to your computer and use it in GitHub Desktop.
Using Queen to solve the math puzzle "SEND + MORE = MONEY"
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
final int m = 1; | |
List<Integer> answer = range(9, 0).except(m).permutations(7).first(new Predicate<List<Integer>>() { | |
@Override | |
public boolean evaluate(final List<Integer> perm) { | |
int s = perm.get(0); | |
int e = perm.get(1); | |
int n = perm.get(2); | |
int d = perm.get(3); | |
int o = perm.get(4); | |
int r = perm.get(5); | |
int y = perm.get(6); | |
return _(s, e, n, d) + _(m, o, r, e) == _(m, o, n, e, y); | |
} | |
private int _(int a, int b, int c, int d) { | |
return 1000 * a + 100 * b + 10 * c + d; | |
} | |
private int _(int a, int b, int c, int d, int e) { | |
return _(a, b, c, d) * 10 + e; | |
} | |
}).getOrElse(Collections.<Integer>emptyList()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment