aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-241/adam-russell/prolog/ch-1.p25
1 files changed, 14 insertions, 11 deletions
diff --git a/challenge-241/adam-russell/prolog/ch-1.p b/challenge-241/adam-russell/prolog/ch-1.p
index a5bef464b4..3a415a2fb0 100644
--- a/challenge-241/adam-russell/prolog/ch-1.p
+++ b/challenge-241/adam-russell/prolog/ch-1.p
@@ -2,17 +2,20 @@ 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([IX, IY, IZ|I], [JY, JZ|J], [], Difference, TripletCount):-
- arithmetic_triplets([IX, IY, IZ|I], [JZ|J], J, Difference, TripletCount).
-arithmetic_triplets([_, IY, IZ|I], [], [], Difference, TripletCount):-
- arithmetic_triplets([IY, IZ|I], [IZ|I], I, Difference, TripletCount).
-arithmetic_triplets([IX, IY, IZ|I], [JY, JZ|J], [KZ|K], Difference, TripletCount):-
- Difference #= JY - IX,
- Difference #= KZ - JY,
- arithmetic_triplets([IX, IY, IZ|I], [JY, JZ|J], K, Difference, TripletCountNext),
+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([IX, IY, IZ|I], [JY, JZ|J], [KZ|K], Difference, TripletCount):-
- (Difference #\= JY - IX; Difference #\= KZ - JY),
- arithmetic_triplets([IX, IY, IZ|I], [JY, JZ|J], K, Difference, TripletCountNext),
+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.