Advertisement
steffffffan

P2_8

Nov 20th, 2022
912
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Prolog 0.37 KB | None | 0 0
  1. %8.
  2. % a) Definiti un predicat care determina succesorul unui numar
  3. % reprezentat cifra cu cifra intr-o lista. De ex: [1 9 3 5 9 9] =>
  4. % [1 9 3 6 0 0]
  5.  
  6. succh([H],[H1],0):-H<9,!,H1 is H+1.
  7. succh([9],[0],1):-!.
  8. succh([H|T],R,C):-
  9.     succh(T,R1,C1), !,
  10.     H1 is (H+C1) mod 10,
  11.     C is (H+C1)//10,
  12.     R=[H1|R1].
  13.  
  14. succs(A,B):-succh(A,B,0),!.
  15. succs(A,[1|B]):-succh(A,B,1).
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement