summaryrefslogtreecommitdiff
path: root/prolog/problems/denotational_semantics/prog_8puzzle_3/common.py
diff options
context:
space:
mode:
Diffstat (limited to 'prolog/problems/denotational_semantics/prog_8puzzle_3/common.py')
-rw-r--r--prolog/problems/denotational_semantics/prog_8puzzle_3/common.py37
1 files changed, 37 insertions, 0 deletions
diff --git a/prolog/problems/denotational_semantics/prog_8puzzle_3/common.py b/prolog/problems/denotational_semantics/prog_8puzzle_3/common.py
new file mode 100644
index 0000000..415dc17
--- /dev/null
+++ b/prolog/problems/denotational_semantics/prog_8puzzle_3/common.py
@@ -0,0 +1,37 @@
+id = 173
+group = 'denotational_semantics'
+number = 82
+visible = True
+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)}.
+'''