1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195
|
/* *\
/
/* Solution *\
/
/* *\
/
/* Version 1.1.1b *\
/
/* *\
/
/******************************************************************************\
/
/* Date : 2018-03-27 04:00:00 *\
/
/* Author : Arknos *\
/
/* Version : 1.1.1b \
*/
/* Description : S.P.I.R. solution *\
/
/******************************************************************************\
/
:- dynamic ( mix/7 ).
:- dynamic ( result/3).
prompt(Prompt) :- prompt1(Prompt).
message(Message) :- write(Message), nl.
dialog(Message,
Prompt,
Response) :- message(Message),
prompt(Prompt),
read(Response).
contact(Name) :- dialog("", "LOGON : ", Name).
who(Dealer) :- dialog("Who ?", "dealer : ", Dealer).
what(What) :- dialog("What ?", "what : ", What).
where(Where) :- dialog("Where ?", "where : ", Where).
when(When) :- dialog("When ?", "when : ", When).
howto(Howto) :- dialog("How to ?", "how to : ", Howto).
quantity(Quantity) :- dialog("How many ?", "how many : ", Quantity).
price(Price) :- dialog("How much ?", "price : ", Price).
situation(Mix) :-
who(Dealer),
what(What),
where(Where),
when(When),
howto(Howto),
quantity(Quantity),
price(Price),
assertz((mix(Dealer, What, Where, When, Howto, Quantity, Price))),
Mix = [Dealer, What, Where, When, Howto, Quantity, Price].
split([Dealer, What, Where, When, Howto, Quantity, Price],
Dealer, What, Where, When, Howto, Quantity, Price).
problem(dealer, Mix, Values) :-
split(Mix, Dealer, What, Where, When, Howto, Quantity, Price),
findall(Value,
mix(Value, What, Where, When, Howto, Quantity, Price), Values).
problem(what, Mix, Values) :-
split(Mix, Dealer, What, Where, When, Howto, Quantity, Price),
findall(Value,
mix(Dealer, Value, Where, When, Howto, Quantity, Price), Values).
problem(where, Mix, Values) :-
split(Mix, Dealer, What, Where, When, Howto, Quantity, Price),
findall(Value,
mix(Dealer, What, Value, When, Howto, Quantity, Price), Values).
problem(when, Mix, Values) :-
split(Mix, Dealer, What, Where, When, Howto, Quantity, Price),
findall(Value,
mix(Dealer, What, Where, Value, Howto, Quantity, Price), Values).
problem(howto, Mix, Values) :-
split(Mix, Dealer, What, Where, When, Howto, Quantity, Price),
findall(Value,
mix(Dealer, What, Where, When, Value, Quantity, Price), Values).
problem(quantity, Mix, Values) :-
split(Mix, Dealer, What, Where, When, Howto, Quantity, Price),
findall(Value,
mix(Dealer, What, Where, When, Howto, Value, Price), Values).
problem(price, Mix, Values) :-
split(Mix, Dealer, What, Where, When, Howto, Quantity, Price),
findall(Value,
mix(Dealer, What, Where, When, Howto, Quantity, Value), Values).
problem(Problem) :- dialog("What is the problem ? ", "problem : ", Problem).
implication(Mix, Problem, Values) :- message("Result searching..."),
problem(Problem, Mix, Values).
problem(Name, Mix, Problem) :- assertz((result(Name, Mix, Problem))).
problem_split([Name, Dealer, What, Where, When, Howto, Quantity, Price, Problem],
Name, [Dealer, What, Where, When, Howto, Quantity, Price], Problem).
split([Name, Mix, Problem], Name, Mix, Problem).
new_deal(Stream, Index) :-
read_string(Stream, "\n", "\r\t", Code, X),
atomic_list_concat(List, ' ', X),
writeln(List),
problem_split(List, Name, Mix, Problem),
write("name : "), writeln(Name),
write("mix : "), writeln(Mix),
write("problem : "), writeln(Problem),
split(Mix, Dealer, What, Where, When, Howto, Quantity, Price),
assertz((mix(Dealer, What, Where, When, Howto, Quantity, Price))),
implication(Mix, Problem, Values),
write("New values : "), write(Values), nl,
problem(Name, Mix, Problem).
read_file(Stream, Size, N) :-
foreach(between(N, Size, Index),
new_deal(Stream, Index)).
situations(Filename, L) :- open(Filename, read, Stream),
Size is 5,
I is 1,
read_file(Stream, Size, I),
close(Stream).
deal :- situation(Mix),
problem(Problem),
implication(Mix, Problem, Values),
write("New values : "), write(Values), nl,
contact(Name),
problem(Name, Mix, Problem).
init :- writeln("Reading database..."),
situations("situations.txt", L).
produit(Q, P, T) :- T is P * Q.
sum(T1, T2, Sum) :- Sum is T1 + T2.
analyze2(L, Index, Sum) :-
writeln("Analyze : "),
nth0(Index, L, Element),
writeln(Element),
nth1(1, Element, Quantity),
nth1(2, Element, Price),
atom_number(Quantity, Q),
atom_number(Price, P),
produit(Q, P, Total),
write("Total = "), writeln(Total),
append([Total], Sum).
element_sum(List, Index, Total) :-
write("nth0 : "),
writeln(Index),
nth0(Index, List, P),
writeln("atom_number"),
atom_number(P, Produit),
sum(0, Produit, Total),
write("Total = "),
writeln(Total).
list_sum([], 0) :- !.
list_sum([T|Q], Sum) :-
list_sum(Q, S),
sum(T, S, Sum).
bilan(Name, Problem, Total) :-
findall([Quantity, Price],
result(Name,
[Dealer, What, Where, When, Howto, Quantity, Price],
Problem),
L),
length(L, L_Length),
Last is L_Length - 1,
append([], T, R),
foreach(between(0, Last, Index),
(analyze2(L, Index, Sum))),
length(Sum, S_Length),
write("Sum_Length : "),
writeln(S_Length),
(S_Length == L_Length ->
true),
%% S_Last is S_Length - 1,
%% foreach(between(0, S_Last, S_Index),
%% (element_sum(Sum, S_Index, Total))).
list_sum(Sum, Total). |
Partager