aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2023-11-06 02:42:24 +0000
committerGitHub <noreply@github.com>2023-11-06 02:42:24 +0000
commit8d6398ebc4b2689e3a6252507e2f06b895b816ee (patch)
tree788c45e660f76fabdb0cf6d0d37fce2569b5d904
parent2f721d0ac78f39cd048c28d8d29c7000d5ea3fa4 (diff)
parent7d7733310f25bd2dfa677e66a130281589b88eb4 (diff)
downloadperlweeklychallenge-club-8d6398ebc4b2689e3a6252507e2f06b895b816ee.tar.gz
perlweeklychallenge-club-8d6398ebc4b2689e3a6252507e2f06b895b816ee.tar.bz2
perlweeklychallenge-club-8d6398ebc4b2689e3a6252507e2f06b895b816ee.zip
Merge pull request #9007 from adamcrussell/challenge-241
CLP solution for 241.1
-rw-r--r--challenge-241/adam-russell/prolog/ch-1.p32
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).