rnprint(0).
rnprint(A) :-
random(0,10,R),
write(R),
nl,
B is A-1,
rnprint(B).
rnlist(0,[]).
rnlist(N,X) :-
R is N-1,
rnlist(R,A),
random(0,10,B),
append(A,[B],X).
%counts occurrences of the given number in the generated list
count(_,[],0).
count(A,[H|T],B) :-
A = H,
count(A,T,K),
B is K + 1.
count(A,[H|T],B) :-
count(A,T,B).
%counts number of digits with single occurrences
single_count([],0).
single_count(A,K) :-
single_2(A,10,C),
K is C.
single_2(_,0,0).
single_2(A,B,K) :-
D is B - 1,
count(D,A,T),
T = 1,
single_2(A,D,C),
K is C + 1.
single_2(A,B,K) :-
D is B - 1,
single_2(A,D,K).
%counts number of digits within list that occur twice
double_count([],0).
double_count(A,B) :-
double_2(A,10,K),
B is K.
double_2(_,0,0).
double_2(A,C,B) :-
Z is C - 1,
count(Z,A,N),
N = 2,
double_2(A,Z,K),
B is K + 1.
double_2(A,C,B) :-
Z is C - 1,
double_2(A,Z,B).
