Data update

This commit is contained in:
Ingy döt Net 2026-02-01 16:33:20 -08:00
parent 5150844a7d
commit 4bb20c9b71
7735 changed files with 38060 additions and 199180 deletions

View file

@ -16,49 +16,49 @@ digits(8).
% tirage(-)
tirage(Ms) :-
% are there previous guesses ?
( bagof([P, R], guess(P,R), Propositions)
-> tirage(Propositions, Ms)
; % First try
tirage_1(Ms)),
!.
% are there previous guesses ?
( bagof([P, R], guess(P,R), Propositions)
-> tirage(Propositions, Ms)
; % First try
tirage_1(Ms)),
!.
% tirage_1(-)
% We choose the first Len numbers
tirage_1(L):-
proposition(Len),
Max is Len-1,
numlist(0, Max, L).
proposition(Len),
Max is Len-1,
numlist(0, Max, L).
% tirage(+,-)
tirage(L, Ms) :-
proposition(Len),
proposition(Len),
length(Ms, Len),
digits(Digits),
digits(Digits),
% The guess contains only this numbers
% The guess contains only this numbers
Ms ins 0..Digits,
all_different(Ms),
all_different(Ms),
% post the constraints
% post the constraints
maplist(placees(Ms), L),
% compute a possible solution
label(Ms).
% compute a possible solution
label(Ms).
% placees(+, +])
placees(Sol, [Prop, [BP, MP]]) :-
V #= 0,
V #= 0,
% compute the numbers of digits in good places
compte_bien_placees(Sol, Prop, V, BP1),
BP1 #= BP,
% compute the numbers of digits in good places
compte_bien_placees(Sol, Prop, V, BP1),
BP1 #= BP,
% compute the numbers of digits inbad places
compte_mal_placees(Sol, Prop, 0, V, MP1),
MP1 #= MP.
% compute the numbers of digits inbad places
compte_mal_placees(Sol, Prop, 0, V, MP1),
MP1 #= MP.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
@ -73,10 +73,10 @@ placees(Sol, [Prop, [BP, MP]]) :-
compte_mal_placees(_, [], _, MP, MP).
compte_mal_placees(Sol, [H | T], N, MPC, MPF) :-
compte_une_mal_placee(H, N, Sol, 0, 0, VF),
MPC1 #= MPC + VF,
N1 is N+1,
compte_mal_placees(Sol, T, N1, MPC1, MPF).
compte_une_mal_placee(H, N, Sol, 0, 0, VF),
MPC1 #= MPC + VF,
N1 is N+1,
compte_mal_placees(Sol, T, N1, MPC1, MPF).
% Here we check one digit of an already done guess
@ -93,22 +93,22 @@ compte_une_mal_placee(_H, _N, [], _, TT, TT).
% digit in the same range, continue
compte_une_mal_placee(H, NH, [_H1 | T], NH, TTC, TTF) :-
NH1 is NH + 1, !,
compte_une_mal_placee(H, NH, T, NH1, TTC, TTF).
NH1 is NH + 1, !,
compte_une_mal_placee(H, NH, T, NH1, TTC, TTF).
% same digit in different places
% increment the counter and continue continue
compte_une_mal_placee(H, NH, [H1 | T], NH1, TTC, TTF) :-
H #= H1,
NH \= NH1,
NH2 is NH1 + 1,
TTC1 #= TTC + 1,
compte_une_mal_placee(H, NH, T, NH2, TTC1, TTF).
H #= H1,
NH \= NH1,
NH2 is NH1 + 1,
TTC1 #= TTC + 1,
compte_une_mal_placee(H, NH, T, NH2, TTC1, TTF).
compte_une_mal_placee(H, NH, [H1 | T], NH1, TTC, TTF) :-
H #\= H1,
NH2 is NH1 + 1,
compte_une_mal_placee(H, NH, T, NH2, TTC, TTF).
H #\= H1,
NH2 is NH1 + 1,
compte_une_mal_placee(H, NH, T, NH2, TTC, TTF).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@ -123,10 +123,10 @@ compte_une_mal_placee(H, NH, [H1 | T], NH1, TTC, TTF) :-
compte_bien_placees([], [], MP, MP).
compte_bien_placees([H | T], [H1 | T1], MPC, MPF) :-
H #= H1,
MPC1 #= MPC + 1,
compte_bien_placees(T, T1, MPC1, MPF).
H #= H1,
MPC1 #= MPC + 1,
compte_bien_placees(T, T1, MPC1, MPF).
compte_bien_placees([H | T], [H1 | T1], MPC, MPF) :-
H #\= H1,
compte_bien_placees(T, T1, MPC, MPF).
H #\= H1,
compte_bien_placees(T, T1, MPC, MPF).

View file

@ -1,21 +1,21 @@
bulls_and_cows :-
retractall('ia.pl':guess(_,_)),
retractall(coups(_)),
assert(coups(1)),
retractall('ia.pl':guess(_,_)),
retractall(coups(_)),
assert(coups(1)),
repeat,
( tirage(Ms)
-> maplist(add_1, Ms, Ms1),
atomic_list_concat(Ms1, Guess),
retract(coups(Coup)),
Coup_1 is Coup + 1,
assert(coups(Coup_1)),
format('~w My guess ~w~n', [Coup, Guess]),
write('Bulls : '), read(Bulls),
write('Cows : '), read(Cows), nl,
assert('ia.pl':guess(Ms, [Bulls, Cows])),
Bulls = 4
; writeln('Sorry, I can''t find a solution !'), true).
repeat,
( tirage(Ms)
-> maplist(add_1, Ms, Ms1),
atomic_list_concat(Ms1, Guess),
retract(coups(Coup)),
Coup_1 is Coup + 1,
assert(coups(Coup_1)),
format('~w My guess ~w~n', [Coup, Guess]),
write('Bulls : '), read(Bulls),
write('Cows : '), read(Cows), nl,
assert('ia.pl':guess(Ms, [Bulls, Cows])),
Bulls = 4
; writeln('Sorry, I can''t find a solution !'), true).
add_1(X, Y) :-
Y is X + 1.
Y is X + 1.