/////////////////////////////////////////////////////////////////////////////// // Simple multiplication /////////////////////////////////////////////////////////////////////////////// // Enigma 1493 Albert Haddad, New Scientist magazine, May 10, 2008 /////////////////////////////////////////////////////////////////////////////// // // In the multiplication shown below, the digits have been replaced by letters // and asterisks. Different letters stand for different digits, the same // letter stands for the same digit, an asterisk can be any digit, and leading // digits cannot be zero. // // * * * // * * * // ----- // * * * // S O * // * * * // ----------- // S I M P L E // ----------- // // What is the six-figure product? // /////////////////////////////////////////////////////////////////////////////// // // Solve the problem by running the query: // // all Simple_Multiplication(simple) // /////////////////////////////////////////////////////////////////////////////// // // Results: // // simple = 102485 // ___ Solution: 1 ___ [00:00:00] __ [Backtracks: 810] ____ // // Number of solutions: 1 Number of backtracks: 56309 // Elapsed time: 00:00:01 // /////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////// // // Replace all asterisks and letters by variables // // x1 x2 x3 // y1 y2 y3 // -------- // z1 z2 z3 // s o u1 // w1 w2 w3 // --------------- // s i m p l e // pred Simple_Multiplication(simple::L[1..]) iff // letters are all different, asterisks not neccesserily... letters::[0..]->>L[0..9] & letters = [s,o,i,m,p,l,e] & asterisks::[0..]->L[0..9] & asterisks = [x1,x2,x3,y1,y2,y3,z1,z2,z3,u1,w1,w2,w3] & // no leading zeros... s <> 0 & x1 <> 0 & y1 <> 0 & w1 <> 0 & z1 <> 0 & // constrain the variables, the way they taught us in // elementary school... top = 100*x1 + 10*x2 + x3 & // top number // multiply the top number by y1... y3 * top = byproduct1 & byproduct1 = 100*z1 + 10*z2 + z3 & // multiply the top number by y2... y2 * top = byproduct2 & byproduct2 = 100*s + 10*o + u1 & // multiply the top number by y3... y1 * top = byproduct3 & byproduct3 = 100*w1 + 10*w2 + w3 & // Add up the three byproducts and we are done... simple = 100000*s + 10000*i + 1000*m + 100*p + 10*l + e & simple = byproduct1 + 10*byproduct2 + 100*byproduct3
This page was created by F1toHTML