% 15.
% a. Define a predicate to determine the predecessor of a number represented as digits in a list.
% Eg.: [1 9 3 6 0 0] => [1 9 3 5 9 9]
% b. For a heterogeneous list, formed from integer numbers and list of numbers, define a predicate to determine
% the predecessor of the every sublist considered as numbers.
% Eg.: [1, [2, 3], 4, 5, [6, 7, 9], 10, 11, [1, 2, 0], 6] =>
% [1, [2, 2], 4, 5, [6, 7, 8], 10, 11, [1, 1, 9] 6]

% zeros(L:list, R:list)
% flow model: (i)
% zeros(l1l2...ln) = {
% 	true if n = 0
%   true if l1 = 0 and zeros(l2l3...ln) = true
% 	false otherwise }


zeros([]).
zeros([H|T]) :- H =:= 0, zeros(T).


% a
% predecessor(L:list, R:list)
% flow model: (i o)
% predecessor(l1l2...ln) = {
% 	[], n = 0
% 	9 U predecessor(l2l3...ln), l1 = 0
% 	(l1 - 1) U l2l3...ln, l1 != 0, zeros(l2l3...ln) = true
% 	l1 U predecessor(l2l3...ln), l1 != 0, zeros(l2l3...ln) = false }
predecessor([], []).
predecessor([H|T], [9|R]) :- zeros(T), H =:= 0, predecessor(T, R).
predecessor([H|T], [H1|R]) :- zeros(T), H1 is H - 1, predecessor(T, R).
predecessor([H|T], [H|R]) :- \+ zeros(T), predecessor(T, R).



% b
% predecessor_heterogeneous(L:list, R:list)
% flow model: (i o)
% predecessor_heterogeneous(l1l2...ln) = {
% 	[], n = 0
% 	predecessor(l1) U predecessor_heterogeneous(l2l3...ln), is_list(l1) = true
% 	l1 U predecessor_heterogeneous(l2l3...ln), is_list(l1) = false }
predecessor_heterogeneous([], []).
predecessor_heterogeneous([H|T], [H1|R]) :- is_list(H), predecessor(H, H1), predecessor_heterogeneous(T, R).
predecessor_heterogeneous([H|T], [H|R]) :- \+ is_list(H), predecessor_heterogeneous(T, R).





