Skip to content

Instantly share code, notes, and snippets.

@bahmanm
Last active August 29, 2015 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bahmanm/b5c80ab3dde14181f639 to your computer and use it in GitHub Desktop.
Save bahmanm/b5c80ab3dde14181f639 to your computer and use it in GitHub Desktop.
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