/////////////////////////////////////////////////////////////////////////////// // Magic planets /////////////////////////////////////////////////////////////////////////////// // Enigma 1396 W. Haigh, New Scientist magazine, 17 June 2006. /////////////////////////////////////////////////////////////////////////////// // // I have allocated distinct positive integers to the letters of the alphabet. // By adding up the values of the letters in their names, I have obtained the // following scores for some members of the solar system: // PLUTO 40, URANUS 36, NEPTUNE 29, SATURN 33, JUPITER 50, MARS 32, EARTH 31, // MOON 36, VENUS 39, MERCURY 33, SUN 18. // // Please send in the value of PLANETS. // /////////////////////////////////////////////////////////////////////////////// // // Solve the problem by running the query: // // all MagicPlanets(planets) // /////////////////////////////////////////////////////////////////////////////// // // Results: // // planets = 52 // ___ Solution: 1 __________________________________ // // planets = 52 // ___ Solution: 2 __________________________________ // // planets = 52 // ___ Solution: 3 __________________________________ // // planets = 52 // ___ Solution: 4 __________________________________ // // Number of solutions: 4 Number of backtracks: 28979 // Elapsed time: 00:00:02 // /////////////////////////////////////////////////////////////////////////////// // // Notes: To see why there are four identical solutions for "planets", // print out the actual values for various letters. The values for // "c" and "y" can be 6 or 7 and "i" and "j" can be 15 or 16. This generates // four permutations, hence four solutions. None of these letters are used in // the word "planets", so all four solutions for "planets" end up being // identical. // /////////////////////////////////////////////////////////////////////////////// pred MagicPlanets(x::L[1..]) iff letters :: [0..]->>L[1..24] & letters = [p,l,u,t,o,r,a,n,s,e,i,m,j,h,v,c,y] & p + l + u + t + o = 40 & u + r + a + n + u + s = 36 & n + e + p + t + u + n + e = 29 & s + a + t + u + r + n = 33 & j + u + p + i + t + e + r = 50 & m + a + r + s = 32 & e + a + r + t + h = 31 & m + o + o + n = 36 & v + e + n + u + s = 39 & m + e + r + c + u + r + y = 33 & s + u + n = 18 & p + l + a + n + e + t + s = x // & PrintLetters(letters) //local proc PrintLetters(a:<[0..]->L) iff Print('\nletters = ',a)
This page was created by F1toHTML