diff options
| author | Adam Russell <ac.russell@live.com> | 2023-11-05 21:38:39 -0500 |
|---|---|---|
| committer | Adam Russell <ac.russell@live.com> | 2023-11-05 21:38:39 -0500 |
| commit | 7d7733310f25bd2dfa677e66a130281589b88eb4 (patch) | |
| tree | b53959d6ea1bd5dd530c4d691ed113bb70061b0a | |
| parent | 85c8d7ba78838ff3e8705c9f647d194891ed05ae (diff) | |
| download | perlweeklychallenge-club-7d7733310f25bd2dfa677e66a130281589b88eb4.tar.gz perlweeklychallenge-club-7d7733310f25bd2dfa677e66a130281589b88eb4.tar.bz2 perlweeklychallenge-club-7d7733310f25bd2dfa677e66a130281589b88eb4.zip | |
CLP solution for 241.1
| -rw-r--r-- | challenge-241/adam-russell/prolog/ch-1.p | 32 |
1 files changed, 12 insertions, 20 deletions
diff --git a/challenge-241/adam-russell/prolog/ch-1.p b/challenge-241/adam-russell/prolog/ch-1.p index 3a415a2fb0..d89386fecf 100644 --- a/challenge-241/adam-russell/prolog/ch-1.p +++ b/challenge-241/adam-russell/prolog/ch-1.p @@ -1,21 +1,13 @@ arithmetic_triplets(Numbers, Difference, TripletCount):- - [X, Y, Z|T] = Numbers, - arithmetic_triplets([X, Y, Z|T], [Y, Z|T], [Z|T], Difference, TripletCount). -arithmetic_triplets([], [], [], _, 0). -arithmetic_triplets(I, [_|J], [], Difference, TripletCount):- - [_|K] = J, - arithmetic_triplets(I, J, K, Difference, TripletCount). -arithmetic_triplets([_|I], [], [], Difference, TripletCount):- - [_|J] = I, - [_|K] = J, - arithmetic_triplets(I, J, K, Difference, TripletCount). -arithmetic_triplets([IH|I], [JH|J], [KH|K], Difference, TripletCount):- - Difference #= JH - IH, - Difference #= KH - JH, - arithmetic_triplets([IH|I], [JH|J], K, Difference, TripletCountNext), - succ(TripletCountNext, TripletCount). -arithmetic_triplets([IH|I], [JH|J], [KH|K], Difference, TripletCount):- - (Difference #\= JH - IH; Difference #\= KH - JH), - arithmetic_triplets([IH|I], [JH|J], K, Difference, TripletCountNext), - TripletCount is TripletCountNext + 0. - + length(Triplet, 3), + member(I, Triplet), + member(J, Triplet), + member(K, Triplet), + fd_domain(Triplet, Numbers), + fd_all_different(Triplet), + Difference #= J - I, + Difference #= K - J, + I #< J, + J #< K, + findall(Triplet, fd_labeling(Triplet), Triplets), + length(Triplets, TripletCount). |
