Also, SWI-Prolog is not exactly the fastest prolog available and its clpfd module is not exactly the fastest CLP(FD) library either... I would not be surprised if some other prolog could run the same program more than an order of magnitude faster!

Here it goes the same program adapted for GNU Prolog. In my machine in runs on five seconds, finding the solutions for the ten pairs of input rows!

different_lists([A|TA], [B|TB]) :- ( A #\= B ; A #= B, different_lists(TA, TB) ). all_different_lists([]). all_different_lists([A|T]) :- all_different_lists(T, A), all_different_lists(T). all_different_lists([], _). all_different_lists([B|T], A) :- different_lists(A, B), all_different_lists(T, A). list_sequence([]). list_sequence([H|T]) :- list_sequence(T, H). list_sequence([], _). list_sequence([B|T], A) :- list_lt(A, B), list_sequence(T, B). list_lt([A|TA], [B|TB]) :- ( A #< B ; A #= B, list_lt(TA, TB) ). domain_from_global_cardinality([], []). domain_from_global_cardinality([Val-_|ET], [Val|DT]) :- domain_from_global_cardinality(ET, DT). global_cardinality(L, Exactly) :- domain_from_global_cardinality(Exactly, Domain), fd_domain(L, Domain), global_cardinality1(Exactly, L). global_cardinality1([], _). global_cardinality1([Val-Rep|T], L) :- fd_exactly(Rep, L, Val), global_cardinality1(T, L). solve([Row1, Row2, Row3, Row4, Row5, Row6, Row7]) :- Row1 = [A1, A2, A3, A4, A5, A6, A7], Row2 = [B1, B2, B3, B4, B5, B6, B7], Row3 = [C1, C2, C3, C4, C5, C6, C7], Row4 = [D1, D2, D3, D4, D5, D6, D7], Row5 = [E1, E2, E3, E4, E5, E6, E7], Row6 = [F1, F2, F3, F4, F5, F6, F7], Row7 = [G1, G2, G3, G4, G5, G6, G7], Col1 = [A1, B1, C1, D1, E1, F1, G1], Col2 = [A2, B2, C2, D2, E2, F2, G2], Col3 = [A3, B3, C3, D3, E3, F3, G3], Col4 = [A4, B4, C4, D4, E4, F4, G4], Col5 = [A5, B5, C5, D5, E5, F5, G5], Col6 = [A6, B6, C6, D6, E6, F6, G6], Col7 = [A7, B7, C7, D7, E7, F7, G7], global_cardinality(Row1, [0-2, 1-2, 2-3]), global_cardinality(Row2, [0-2, 1-2, 2-3]), global_cardinality(Row3, [0-2, 1-2, 2-3]), global_cardinality(Row4, [0-2, 1-2, 2-3]), global_cardinality(Row5, [0-2, 1-2, 2-3]), global_cardinality(Row6, [0-2, 1-2, 2-3]), global_cardinality(Row7, [0-2, 1-2, 2-3]), global_cardinality(Col1, [0-2, 1-2, 2-3]), global_cardinality(Col2, [0-2, 1-2, 2-3]), global_cardinality(Col3, [0-2, 1-2, 2-3]), global_cardinality(Col4, [0-2, 1-2, 2-3]), global_cardinality(Col5, [0-2, 1-2, 2-3]), global_cardinality(Col6, [0-2, 1-2, 2-3]), global_cardinality(Col7, [0-2, 1-2, 2-3]), all_different_lists([Row3, Row4, Row5, Row6, Row7], Row1), all_different_lists([Row3, Row4, Row5, Row6, Row7], Row2), list_sequence([Row3, Row4, Row5, Row6, Row7]), all_different_lists([Col1, Col2, Col3, Col4, Col5, Col6, Col7] +), fd_labeling([A1, A2, A3, A4, A5, A6, A7, B1, B2, B3, B4, B5, B6, B7, C1, C2, C3, C4, C5, C6, C7, D1, D2, D3, D4, D5, D6, D7, E1, E2, E3, E4, E5, E6, E7, F1, F2, F3, F4, F5, F6, F7, G1, G2, G3, G4, G5, G6, G7]). time(G) :- cpu_time(Start), call(G), cpu_time(End), S is End - Start, write(time(goal(G), ms(S))), nl. solve(R1, R2, L) :- findall(-, solve([R1, R2 | _]), All), length(All, L). tryme([]). tryme([H|T]) :- H = [R1, R2], write('searching...'), nl, time(solve(R1, R2, L)), L120 is L * 120, write(solve(R1, R2, L, L120)), nl, tryme(T). tryme :- tryme([[[2, 1, 0, 0, 2, 2, 1], [0, 2, 2, 1, 1, 0, 2]], [[2, 0, 0, 2, 2, 1, 1], [2, 0, 1, 2, 2, 1, 0]], [[2, 1, 0, 1, 2, 0, 2], [2, 2, 1, 1, 2, 0, 0]], [[2, 1, 0, 1, 2, 2, 0], [1, 2, 0, 2, 1, 2, 0]], [[0, 2, 0, 1, 2, 1, 2], [1, 2, 0, 2, 1, 0, 2]], [[2, 0, 0, 1, 2, 2, 1], [2, 1, 1, 0, 2, 2, 0]], [[1, 2, 2, 0, 0, 2, 1], [2, 0, 1, 0, 1, 2, 2]], [[2, 2, 1, 1, 0, 2, 0], [1, 0, 2, 1, 2, 0, 2]], [[2, 0, 1, 1, 2, 0, 2], [0, 1, 2, 2, 0, 1, 2]], [[0, 2, 2, 0, 1, 2, 1], [1, 0, 1, 2, 2, 2, 0]]]).

In reply to Re^5: Seven by seven farming puzzle by salva
in thread Seven by seven farming puzzle by ambrus

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.