Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Scheme:
- (define (pickNumToAdd M N)
- (if (null? M) 0
- (+ (nth N (car M)) (pickNumToAdd (cdr M) N))))
- Prolog:
- pickNumToAdd(M,N,Out) :-
- M==[] ->
- Out = 0
- ;
- (
- [CAR|CDR] = M, nth(N,CAR,NTH),
- pickNumToAdd(CDR,N,MID),
- Out is NTH + MID
- ).
- Frontal:
- f_nth(A,[A|B],1).
- f_nth(ListItemValue,[A|B],N) :- N>0, N1 is N-1, f_nth(ListItemValue,B,N1).
- f_car(CAR,[CAR|_]).
- f_cdr(CDR,[_|CDR]).
- f_pickNumToAdd(Out,M,N) :-
- M==[] ->
- Out = 0
- ;
- (
- f_car(CAR,M), f_nth(NTH, N, CAR),
- f_cdr(CDR,M),
- f_pickNumToAdd(MID,CDR,N),
- Out is NTH + MID
- ).
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement