Here is how Mathematica can be used to solve New Scientist Enigma number 1463 in the 6 October 2007 issue. Because this problem is so easy to solve I don't bother to make use of symmetry to simplify the search for a solution.
Generate a list of permutations of the digits 1, 2, ..., 9.
(digitperms = Permutations[Range[9]]) // Length
362880
Arrange each of these sets of 9 digits into a 3 by 3 array and generate the corresponding 12 3-digit numbers by reading rows and columns both forwards and backwards.
(numbers = Map[Flatten[Map[{FromDigits[#], FromDigits[Reverse[#]]}&, Join[Partition[#,3], Transpose[Partition[#,3]]]], 1]&, digitperms]) // Length
362880
Select the cases which satisfy the required divisibility conditions.
(numbers2 = Select[numbers, Apply[And, Table[Mod[Count[Map[Mod[#,i]&, #], 0], i]==0, {i,9}]]&]) // Length
8
Extract the minimum and maximum 3-digit numbers from these (symmetrically related) results.
{Min[#], Max[#]}&[numbers2]
{164, 971}
No comments:
Post a Comment