#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Copyright (C) 2014 Mick Krippendorf <m.krippendorf@freenet.de>

__version__ = '0.2.3a'
__date__ = '2014-09-27'
__author__ = 'Mick Krippendorf <m.krippendorf@freenet.de>'
__license__ = 'MIT'


from hornet import *

from hornet.symbols import (
    queens, solution, noattack, template, Others,
    X, Y, Z, X1, Y1, Y2, Y3, Y4, Y5, Y6, Y7, Y8, S, Ys, Zs,
)


def main():

    db = Database()

    db.tell(

        queens(S) <<
            template(S) &
            solution(S, _),

        solution([_/Y], Ys) << select(Y, [1, 2, 3, 4, 5, 6, 7, 8], Ys),

        solution([X/Y|Others], Ys) <<
            solution(Others, Zs) &
            select(Y, Zs, Ys) &
            noattack(X/Y, Others),

        noattack(_,[]),

        noattack(X/Y,[X1/Y1|Others]) <<
            arithemtic_not_equal(Y, Y1) &
            arithemtic_not_equal(Y1 - Y, X1 - X) &
            arithemtic_not_equal(Y1 - Y, X - X1) &
            noattack(X/Y,Others),

        template([1/Y1, 2/Y2, 3/Y3, 4/Y4, 5/Y5, 6/Y6, 7/Y7, 8/Y8]),

    )

    for subst in db.ask(queens(S)):
        print(subst[S])
        #if not input('more?').lower().strip().startswith('y'):
            #break


if __name__ == '__main__':
    main()

@@ -323,38 +323,28 @@
 ck, 
-template, Others,%0A   
+Rest, Nums, S,
  X, Y,
- Z,
  X1,
@@ -352,44 +352,22 @@
 Y1, 
-Y2, Y3, Y4, Y5, Y6, Y7, Y8, S, Ys, Z
+Xs, Ys, Y1s, Q
 s,%0A)
@@ -454,51 +454,52 @@
     
-template(S) &%0A            solution(S, _),%0A%0A
+equal(%5B1, 2, 3, 4, 5, 6, 7, 8%5D, Nums) &%0A    
     
@@ -515,60 +515,55 @@
 ion(
-%5B_/Y%5D, Ys) %3C%3C select(Y, %5B1, 2, 3, 4, 5, 6, 7, 8%5D, Ys
+Nums, Nums, %5B%5D, Qs) &%0A            reverse(Qs, S
 ),%0A%0A
@@ -585,22 +585,23 @@
 n(%5BX
-/Y%7COthers%5D, Ys
+%7CXs%5D, Ys, Qs, S
 ) %3C%3C
@@ -618,25 +618,23 @@
    s
-olution(Others, Z
+elect(Y, Ys, Y1
 s) &
@@ -650,23 +650,23 @@
     
-select(Y, Zs, Y
+noattack(X/Y, Q
 s) &
@@ -682,40 +682,48 @@
     
-noattack(X/Y, Others
+solution(Xs, Y1s, %5BX/Y%7CQs%5D, S
 ),%0A
-%0A
         
 noat
@@ -722,21 +722,29 @@
     
-noattack(_,%5B%5D
+solution(%5B%5D, %5B%5D, S, S
 ),%0A%0A
@@ -768,21 +768,20 @@
 X/Y,
+ 
 %5BX1/Y1%7C
-Others
+Rest
 %5D) %3C
@@ -955,26 +955,24 @@
 X/Y,
-Others
+ Rest
 ),%0A
-%0A
         
 temp
@@ -971,64 +971,21 @@
     
-template(%5B1/Y1, 2/Y2, 3/Y3, 4/Y4, 5/Y5, 6/Y6, 7/Y7, 8/Y8
+noattack(_, %5B
 %5D),%0A

Version 0.2.3a