summaryrefslogtreecommitdiff
path: root/prolog/problems/denotational_semantics/prog_8puzzle_3/common.py
blob: 494f62815d0d3cf6734226d23f2c6d4591e92b31 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# coding=utf-8

id = 173
number = 82
visible = False
facts = 'denotational_semantics_aux__predicates'

solution = '''\
prog_8puzzle(R0 --> R) -->
    [begin],
     { findblank(R0,C0) },
     instructs173(((R0,C0) --> (R,_C))),
    [end].

instructs173((R0,C0) --> (R,C)) -->
  instr173((R0,C0) --> (R,C)).
instructs173((R0,C0) --> (R,C)) -->
  instr173((R0,C0) --> (R1,C1)), instructs173((R1,C1) --> (R,C)).

instr173((R0,C0) --> (R,C)) -->
  [left], {Pos is (C0-1) mod 3,
            (Pos>0, C is C0-1, swap(R0,C0,C,R)
           ;
             Pos=0, C=C0, R=R0)}.
instr173((R0,C0) --> (R,C)) -->
  [right], {Pos is (C0-1) mod 3,
             (Pos<2, C is C0+1, swap(R0,C0,C,R)
            ;
              Pos=2, C=C0, R=R0)}.
instr173((R0,C0) --> (R,C)) -->
  [up], { (C0>3, C is C0-3, swap(R0,C0,C,R)
         ;
           C0=<3, C=C0, R=R0)}.
instr173((R0,C0) --> (R,C)) -->
  [down], { (C0=<6, C is C0+3, swap(R0,C0,C,R)
           ;
             C0>6, C=C0, R=R0)}.
'''