Post Reply 
July 2018 little math problem
07-26-2018, 12:16 AM (This post was last modified: 07-26-2018 04:53 PM by Albert Chan.)
Post: #4
RE: July 2018 little math problem
(07-25-2018 10:27 PM)Thomas Klemm Wrote:  I just used brute force.

I did solved Thomas third solution by hand.

If using computer is allowed, I would use Picat Programming Language
It is great for puzzle solving, and very fast (below code take 0.12 second to run)

Code:
import cp.                   % zigzag4.pi, 4 sums added to same number S
main => go, fail; true.      % fail forced Picat to search all solutions
go => Vars = [A,B,C,D,E,F,G,H,I],
      Vars :: 1..9,
      all_different(Vars),
      A + B + C #= S,
      E + D + C #= S,
      E + F + G #= S,
      I + H + G #= S,
      solve(Vars), 
      writeln(Vars).

%
% *** solutions below ***

     1    [1,7,6,5,3,9,2,4,8]
     2    [1,7,6,5,3,9,2,8,4]
     3    [1,7,8,6,2,5,9,3,4]
     4    [1,7,8,6,2,5,9,4,3]
     5    [1,7,9,2,6,3,8,4,5]
     6    [1,7,9,2,6,3,8,5,4]
     7    [1,8,7,6,3,4,9,2,5]
     8    [1,8,7,6,3,4,9,5,2]
     9    [1,9,4,8,2,7,5,3,6]
    10    [1,9,4,8,2,7,5,6,3]
    11    [1,9,6,2,8,3,5,4,7]
    12    [1,9,6,2,8,3,5,7,4]
    13    [2,5,9,4,3,6,7,1,8]
    14    [2,5,9,4,3,6,7,8,1]
    15    [2,6,8,1,7,5,4,3,9]
    16    [2,6,8,1,7,5,4,9,3]
    17    [2,8,4,9,1,7,6,3,5]
    18    [2,8,4,9,1,7,6,5,3]
    19    [2,8,6,1,9,3,4,5,7]
    20    [2,8,6,1,9,3,4,7,5]
    21    [2,9,3,4,7,6,1,5,8]
    22    [2,9,3,4,7,6,1,8,5]
    23    [3,4,9,5,2,6,8,1,7]
    24    [3,4,9,5,2,6,8,7,1]
    25    [3,5,6,7,1,9,4,2,8]
    26    [3,5,6,7,1,9,4,8,2]
    27    [3,6,5,7,2,8,4,1,9]
    28    [3,6,5,7,2,8,4,9,1]
    29    [3,9,1,8,4,7,2,5,6]
    30    [3,9,1,8,4,7,2,6,5]
    31    [3,9,2,4,8,5,1,6,7]
    32    [3,9,2,4,8,5,1,7,6]
    33    [3,9,4,5,7,1,8,2,6]
    34    [3,9,4,5,7,1,8,6,2]
    35    [4,3,9,5,2,6,8,1,7]
    36    [4,3,9,5,2,6,8,7,1]
    37    [4,5,8,3,6,2,9,1,7]
    38    [4,5,8,3,6,2,9,7,1]
    39    [4,7,5,3,8,2,6,1,9]
    40    [4,7,5,3,8,2,6,9,1]
    41    [4,8,2,9,3,5,6,1,7]
    42    [4,8,2,9,3,5,6,7,1]
    43    [5,2,9,4,3,6,7,1,8]
    44    [5,2,9,4,3,6,7,8,1]
    45    [5,3,6,7,1,9,4,2,8]
    46    [5,3,6,7,1,9,4,8,2]
    47    [5,4,8,3,6,2,9,1,7]
    48    [5,4,8,3,6,2,9,7,1]
    49    [5,6,2,7,4,8,1,3,9]
    50    [5,6,2,7,4,8,1,9,3]
    51    [5,7,4,3,9,1,6,2,8]
    52    [5,7,4,3,9,1,6,8,2]
    53    [5,8,1,6,7,4,3,2,9]
    54    [5,8,1,6,7,4,3,9,2]
    55    [6,2,8,1,7,5,4,3,9]
    56    [6,2,8,1,7,5,4,9,3]
    57    [6,3,5,7,2,8,4,1,9]
    58    [6,3,5,7,2,8,4,9,1]
    59    [6,5,2,7,4,8,1,3,9]
    60    [6,5,2,7,4,8,1,9,3]
    61    [6,7,1,5,8,4,2,3,9]
    62    [6,7,1,5,8,4,2,9,3]
    63    [7,1,6,5,3,9,2,4,8]
    64    [7,1,6,5,3,9,2,8,4]
    65    [7,1,8,6,2,5,9,3,4]
    66    [7,1,8,6,2,5,9,4,3]
    67    [7,1,9,2,6,3,8,4,5]
    68    [7,1,9,2,6,3,8,5,4]
    69    [7,4,5,3,8,2,6,1,9]
    70    [7,4,5,3,8,2,6,9,1]
    71    [7,5,4,3,9,1,6,2,8]
    72    [7,5,4,3,9,1,6,8,2]
    73    [7,6,1,5,8,4,2,3,9]
    74    [7,6,1,5,8,4,2,9,3]
    75    [8,1,7,6,3,4,9,2,5]
    76    [8,1,7,6,3,4,9,5,2]
    77    [8,2,4,9,1,7,6,3,5]
    78    [8,2,4,9,1,7,6,5,3]
    79    [8,2,6,1,9,3,4,5,7]
    80    [8,2,6,1,9,3,4,7,5]
    81    [8,4,2,9,3,5,6,1,7]
    82    [8,4,2,9,3,5,6,7,1]
    83    [8,5,1,6,7,4,3,2,9]
    84    [8,5,1,6,7,4,3,9,2]
    85    [9,1,4,8,2,7,5,3,6]
    86    [9,1,4,8,2,7,5,6,3]
    87    [9,1,6,2,8,3,5,4,7]
    88    [9,1,6,2,8,3,5,7,4]
    89    [9,2,3,4,7,6,1,5,8]
    90    [9,2,3,4,7,6,1,8,5]
    91    [9,3,1,8,4,7,2,5,6]
    92    [9,3,1,8,4,7,2,6,5]
    93    [9,3,2,4,8,5,1,6,7]
    94    [9,3,2,4,8,5,1,7,6]
    95    [9,3,4,5,7,1,8,2,6]
    96    [9,3,4,5,7,1,8,6,2]
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
July 2018 little math problem - pier4r - 07-25-2018, 08:52 PM
RE: July 2018 little math problem - Albert Chan - 07-26-2018 12:16 AM
RE: July 2018 little math problem - DavidM - 07-26-2018, 04:03 AM
RE: July 2018 little math problem - DavidM - 07-26-2018, 03:38 PM
RE: July 2018 little math problem - pier4r - 07-26-2018, 12:36 PM
RE: July 2018 little math problem - pier4r - 07-27-2018, 10:03 AM
RE: July 2018 little math problem - DavidM - 07-28-2018, 04:22 PM
RE: July 2018 little math problem - pier4r - 08-01-2018, 02:13 PM



User(s) browsing this thread: 1 Guest(s)