Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Solve the constraint equation: A + B = CD - E = FG
/*
* Solve the equation A + B = CD - E = FG
* WHERE A..G in [0,1,2,3,7,8,9]
* AND CD = 10*C + D
* AND FG = 10*F + G
* AND C not 0 and F not 0
* AND different letters are different digits
*/
[0,1,2,3,7,8,9].permutations().findAll {
def (a,b,c,d,e,f,g) = it
def v1 = a + b
def v2 = 10 * c + d - e
def v3 = 10 * f + g
(c != 0) && (f != 0) && (v1 == v2) && (v1 == v3)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment