oops, without reading the spoolers I didn't notice the first two rows were given!

Taking that into account...

:- use_module(library(clpfd)). different_lists([A|TA], [B|TB]) :- ( 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). 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], Row1 = [2, 1, 0, 0, 2, 2, 1], Row2 = [0, 2, 2, 1, 1, 0, 2], % Col1 = [2, 0, 0, 1, 1, 2, 2], 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([Row1, Row2, Row3, Row4, Row5, Row6, Row7]), all_different_lists([Col1, Col2, Col3, Col4, Col5, Col6, Col7]), label([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]). tryme :- writeln('searching...'), time(solve(S)), writeln(S).
and running it...
?- tryme. searching... % 281,537 inferences, 0.180 CPU in 0.183 seconds (98% CPU, 1564094 Lip +s) [[2, 1, 0, 0, 2, 2, 1], [0, 2, 2, 1, 1, 0, 2], [1, 0, 0, 1, 2, 2, 2], +[1, 2, 1, 0, 0, 2, 2], [0, 1, 2, 2, 2, 0, 1], [2, 0, 2, 2, 1, 1, 0], +[2, 2, 1, 2, 0, 1, 0]] true.
So, the problem is solved in less than 200 miliseconds!

update: constraints reordered to improve performance slighly

update: oops2, wrong problem again...


In reply to Re^2: 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.