feat: 1522 l2 notes

This commit is contained in:
2024-02-01 08:26:59 +08:00
parent e790a1f29e
commit 113700eac3
7 changed files with 386 additions and 15 deletions

View File

@@ -215,9 +215,7 @@ nth(Idx, [_|Tail], Elem) :-
Idx1 is Idx - 1,
nth(Idx1, Tail, Elem).
% Taufiq
nth(0, [V | _], V) :- !.
nth(I, [_|T], V) :- nth(I1, T, V), I is I1 + 1, I > 0.
%%%%%%%%%%%%%%
@@ -258,9 +256,6 @@ pos_helper(Target, [_|Tail], Acc, Index) :-
Acc1 is Acc + 1,
pos_helper(Target, Tail, Acc1, Index).
% Taufiq
pos(X, [X | _], 0).
pos(X, [_ | T], I) :- pos(X, T, I1), I is I1 + 1.
%%%%%%%%%%%%%%
@@ -294,9 +289,6 @@ all_pos_helper(Target, [_|Tail], Acc, Rest) :-
Acc1 is Acc + 1,
all_pos_helper(Target, Tail, Acc1, Rest).
% Taufiq
all_pos(X, L, []) :- not(member(X, L)).
all_pos(X, L, LI) :- bagof(I, pos(X, L, I), LI).
%%%%%%%%%%%%%%