HomeHome More SamplesMore Samples
///////////////////////////////////////////////////////////////////////////////
//
// Charles W. Trigg
// PI MU EPSILON JOURNAL, Valume 6, Fall 1977, Number 5
//
// From the following square array of the first 25 positive integers, 
// choose five, no two of the same row or column, so that the maximum of
// the five elements is as small as possible.
//
//    2 13 16 11 23
//   15  1  9  7 10
//   14 12 21 24  8
//    3 25 22 18  4
//   20 19  6  5 17
//
///////////////////////////////////////////////////////////////////////////////
//
//  Using the source code below and running the query
//
//      Five_Elements()
//
//  will generate the following solution:
//
//      Sum:29 [3 1 6 11 8]
//
///////////////////////////////////////////////////////////////////////////////

proc Five_Elements() iff
    min sum, e0,e1,e2,e3,e4
        a :: [0..4]->[0..4]->L[1..25] & 

        a = [[ 2, 13, 16, 11, 23],
             [15,  1,  9,  7, 10],
             [14, 12, 21, 24,  8],
             [ 3, 25, 22, 18,  4], 
             [20, 19,  6,  5, 17]] &

        e0 = a(i0,j0) & e1 = a(i1,j1) & e2 = a(i2,j2) & e3 = a(i3,j3) & e4 = a(i4,j4) &
        e0 + e1 + e2 + e3 + e4 = sum &
        _AllDifferent(i0,i1,i2,i3,i4) & _AllAscending(j0,j1,j2,j3,j4)
    end & 
    Print('Sum:',sum) & Print(' [',e0,' ',e1,' ',e2,' ',e3,' ',e4,']')





This page was created by F1toHTML