Created
October 5, 2016 07:35
-
-
Save eugeneai/f4645c25aa2fe2045036fd484cceb0a8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% L=[a,b,c,d,e,3,5,7,2,[8,6,9]]. | |
% L=[X|T], X=a, T=[b,c,d.....]. | |
% [] | |
% X принадл. списку, если он - голова эт списка. | |
member(X, [X|_]). | |
% X принадлежит списку, если X принадл. хвосту списка. | |
member(X, [_|T]):-member(X,T). | |
% +List, -Sum | |
sum([], 0). | |
sum([X|T], S):- sum(T,ST), S = X + ST. | |
min([X],X). | |
min([X|T], X):-min(T,M), X<M. | |
min([X|T], M):-min(T,M), X>=M. | |
bs(L,S):- | |
x(L,L1), !, bs(L1,S). | |
bs(L,L). | |
x([X,Y|T],[Y,X|T]):-X>Y,!. | |
x([X|T],[X|T1]):-x(T,T1). | |
t(1,1). | |
t(8,8). | |
t(0,0). | |
t(2,5). | |
t(5,2). | |
t(6,9). | |
t(9,6). | |
v(1). | |
v(8). | |
v(0). | |
p([X]):-v(X). | |
p([X,Y]):-t(X,Y). | |
p([X|T]):-t(X,Y),cut(T,Y, T1), p(T1). | |
cut([X],X,[]). | |
cut([Y|T],X,[Y|T1]):-cut(T,X,T1). | |
app([],L,L). | |
app([X|T1],L2,[X|T3]):-app(T1,L2,T3). | |
d(C,X,0):-atom(C), C\=X,!. | |
d(X,X,1):-!. | |
d(sin(E), X, cos(E)*DE):- | |
d(E,X,DE). | |
d(cos(E), X, 0-sin(E)*DE):- | |
d(E,X,DE). | |
d(ln(E), X, DE/E):- | |
d(E,X,DE). | |
d(E^N, X, N*E^N1*DE):- | |
d(E,X,DE), N1 is N-1. | |
d(A + B, X, DA + DB):- | |
d(A, X, DA), d(B, X, DB). | |
d(A - B, X, DA - DB):- | |
d(A, X, DA), d(B, X, DB). | |
d(A * B, X, A*DB + B*DA):- | |
d(A, X, DA), d(B, X, DB). | |
d(A / B, X, (A*DB - B*DA)/(B^2)):- | |
d(A, X, DA), d(B, X, DB). | |
red(E,E1):- | |
r(E,E2),!,red(E2,E1). | |
red(E,E). | |
r(0*_,0). | |
r(_*0,0). | |
r(1*X,X). | |
r(X*1,X). | |
r(X+0,X). | |
r(0+X,X). | |
r(X*X, X^2). | |
r(X*X^N, X^N1):-N1 is N+1. | |
% article ::== "a" | "the" | |
% noun ::== "cow" | "tail" | |
% verb ::== "walks" | "shakes" | |
% -> sentence ::= noun_group verb_group | |
% noun_group ::== article noun | |
% verb_group ::== verb noun_group | |
% a cow shakes the tail | |
% | |
g(sentence, I, O):- | |
g(noun_group,I,R), | |
g(verb_group,R,O). | |
g(noun_group, I,O):-g(article,I,R), g(noun,R,O). | |
g(noun_group, I,O):-g(noun,I,O). | |
g(verb_group, I,O):-g(verb, I,R),g(noun_group,R,O). | |
g(noun, [X|T],T):-noun(X). | |
g(verb, [X|T],T):-verb(X). | |
g(article, [X|T],T):-article(X). | |
noun(cow). | |
noun(tail). | |
article(the). | |
article(a). | |
verb(shakes). | |
verb(walks). | |
num(X):-member(X,[0,1,2,3,4,5,6,7,8,9]). | |
lucky([A,B,C, D,E,F]):- | |
A is F+B+C-D-E, | |
num(A). | |
gen([]). | |
gen([X|T]):-gen(T),num(X). | |
lticket([A|L]):-L=[_,_, _,_,_], | |
gen(L),lucky([A|L]). | |
tickets(N):-findall(X,lticket(X),L), len(L,N). | |
len([],0). | |
len([_|T],N):-len(T,M),N is M+1. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment