Artificial Intelligence - هوش مصنوعی

Artificial Intelligence - هوش مصنوعی (http://artificial.ir/intelligence/)
-   Prolog (http://artificial.ir/intelligence/forum124.html)
-   -   کمک (http://artificial.ir/intelligence/thread13010.html)

vahid_lived ۰۶-۱۷-۱۳۹۳ ۰۵:۵۲ بعد از ظهر

کمک
 
سلام به همه عزیزان ، از دوستانی که به پرولوگ آشنایی کامل دارند میخواستم

نحوه عملکرد کد زیر رو توضیح دهند : (خط به خط چی کار می کند ؟) خواهشن سریع جواب بدین همین کد رو باید برای استاد توضیح بدم

/* queens(N,Queens) :-
Queens is a placement that solves the N queens problem,
Represented as a permutation of the list of numbers [1,2,…,N]. */
queens(N,Qs) :- range(1,N,Ns), permutation(Ns,Qs), safe(Qs).
/* safe(Qs) :- the placement Qs is safe. */
safe([Q|Qs]) :- safe(Qs), not attack(Q,Qs).
safe([]).
attack(X,Xs) :- attack (X,1,Xs).
attack(X,N,[Y|Ys]) :- X is Y+N ; X is Y-N.
attack (X
permutation(Xs,[Z|Zs]) :- select(Z,Xs,Ys), permutation(Ys,Zs).
permutation([],[]).
select(X,[X|Xs],Xs).
select(X,[Y|Ys],[Y|Zs]) :- select(X,Ys,Zs).
range(M,N,[M|Ns]) :- M < N, M1 is M+1, range(M1,N,Ns).
range(N,N,[N]).


زمان محلي شما با تنظيم GMT +3.5 هم اکنون ۱۰:۰۴ بعد از ظهر ميباشد.

Powered by vBulletin® Version 3.8.3
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0 ©2007, Crawlability, Inc.