Ich arbeite mich gerade in Pyke ein.
Pyke ist eine Library / Modul um unter Python Prolog also logische Programmierung zu erreichen

Und nach Menschen die schon etwas Ahnung in der Matterie haben

Ein gut gelaunter
Mungo 1981


Code: Alles auswählen
from hornet import Database, let, select, _, arithmetic_not_equal
from hornet.symbols import (
queens, solution, noattack, Rest, Ns, S, X, Y, X1, Y1, Xs, Ys, Y0s, Qs,
)
def main():
db = Database()
db.tell(
queens(S) <<
let(Ns, [i + 1 for i in range(6)]) &
solution(Ns, Ns, [], S),
solution([X|Xs], Y0s, Qs, [X/Y|S]) <<
select(Y, Y0s, Ys) &
noattack(X/Y, Qs) &
solution(Xs, Ys, [X/Y|Qs], S),
solution([], _, _, []),
noattack(X/Y, [X1/Y1|Rest]) <<
arithmetic_not_equal(Y, Y1) &
arithmetic_not_equal(Y1 - Y, X1 - X) &
arithmetic_not_equal(Y1 - Y, X - X1) &
noattack(X/Y, Rest),
noattack(_, []),
)
for subst in db.ask(queens(S)):
print(subst[S])
if __name__ == '__main__':
main()
Code: Alles auswählen
[1 / 2, 2 / 4, 3 / 6, 4 / 1, 5 / 3, 6 / 5]
[1 / 3, 2 / 6, 3 / 2, 4 / 5, 5 / 1, 6 / 4]
[1 / 4, 2 / 1, 3 / 5, 4 / 2, 5 / 6, 6 / 3]
[1 / 5, 2 / 3, 3 / 1, 4 / 6, 5 / 4, 6 / 2]