From 7d7733310f25bd2dfa677e66a130281589b88eb4 Mon Sep 17 00:00:00 2001 From: Adam Russell Date: Sun, 5 Nov 2023 21:38:39 -0500 Subject: CLP solution for 241.1 --- challenge-241/adam-russell/prolog/ch-1.p | 32 ++++++++++++-------------------- 1 file 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). -- cgit