/////////////////////////////////////////////////////////////////////////////// // Reverse division /////////////////////////////////////////////////////////////////////////////// // Enigma 1557 Richard England, New Scientist magazine, August 8, 2009 /////////////////////////////////////////////////////////////////////////////// // // 1. What is the four-digit integer divisible by 11 and 13 whose reverse // is a larger integer also divisible by 11 and 13? // // 2. What is the four-digit integer divisible by 17 and 19 whose reverse // is a larger integer also divisible by 17 and 19? // // Neither of your answers may have a leading zero. // /////////////////////////////////////////////////////////////////////////////// // // Solve the problem by running the query: // // all Enigma_1557(n1,n2) // /////////////////////////////////////////////////////////////////////////////// // // Results: // // // n1 = 1859 // n2 = 3876 // ___ Solution: 1 ___ [00:00:00] __ [Backtracks: 20991] ____ // // Number of solutions: 1 Number of backtracks: 28987 // Elapsed time: 00:00:00 // /////////////////////////////////////////////////////////////////////////////// local Digit = L[0..9] pred Enigma_1557(n1::L,n2::L) iff a1::Digit & b1::Digit & c1::Digit & d1::Digit & n1 = a1*1000 + b1*100 + c1*10 + d1 & a1 <> 0 & n1 mod 11 = 0 & n1 mod 13 = 0 & n1r = d1*1000 + c1*100 + b1*10 + a1 & d1 <> 0 & n1r mod 11 = 0 & n1r mod 13 = 0 & n1r > n1 & a2::Digit & b2::Digit & c2::Digit & d2::Digit & n2 = a2*1000 + b2*100 + c2*10 + d2 & a2 <> 0 & n2 mod 17 = 0 & n2 mod 19 = 0 & n2r = d2*1000 + c2*100 + b2*10 + a2 & d2 <> 0 & n2r mod 17 = 0 & n2r mod 19 = 0 & n2r > n2
This page was created by F1toHTML