simplify all_diff
This commit is contained in:
parent
414d419212
commit
136e49c2a0
1 changed files with 4 additions and 10 deletions
14
day6.m
14
day6.m
|
@ -12,22 +12,16 @@
|
|||
:- import_module list.
|
||||
:- import_module maybe.
|
||||
|
||||
|
||||
:- func uniq(list(T)) = list(T).
|
||||
uniq([]) = [].
|
||||
uniq([X | Xs]) = Ys :-
|
||||
Ys0 = uniq(Xs),
|
||||
(if member(X, Ys0) then Ys = Ys0 else Ys = [X | Ys0]).
|
||||
|
||||
:- pred alldiff(list(T)::in) is semidet.
|
||||
alldiff(Xs) :- Xs = uniq(Xs).
|
||||
:- pred all_diff(list(T)::in) is semidet.
|
||||
all_diff([]).
|
||||
all_diff([X | Xs]) :- not member(X, Xs), all_diff(Xs).
|
||||
|
||||
:- pred window(int::in, list(T)::in, int::out, list(T)::out) is nondet.
|
||||
window(Len, In, 0, Out) :- take(Len, In, Out).
|
||||
window(Len, [_|In], I + 1, Out) :- window(Len, In, I, Out).
|
||||
|
||||
:- pred start_index(int::in, list(T)::in, int::out) is cc_nondet.
|
||||
start_index(Len, Input, Index) :- window(Len, Input, Index, Out), alldiff(Out).
|
||||
start_index(Len, Input, Index) :- window(Len, Input, Index, Out), all_diff(Out).
|
||||
|
||||
:- func length(part) = int.
|
||||
length(one) = 4.
|
||||
|
|
Loading…
Reference in a new issue