diff options
| author | Adam Russell <ac.russell@live.com> | 2023-11-05 18:57:17 -0500 |
|---|---|---|
| committer | Adam Russell <ac.russell@live.com> | 2023-11-05 18:57:17 -0500 |
| commit | 85c8d7ba78838ff3e8705c9f647d194891ed05ae (patch) | |
| tree | c9b08c18d2809448d39d55eee4f789703b1fdc5f /challenge-241 | |
| parent | b1a13353882d5d223e3d6c3ba967d9eb6d7dd5cd (diff) | |
| download | perlweeklychallenge-club-85c8d7ba78838ff3e8705c9f647d194891ed05ae.tar.gz perlweeklychallenge-club-85c8d7ba78838ff3e8705c9f647d194891ed05ae.tar.bz2 perlweeklychallenge-club-85c8d7ba78838ff3e8705c9f647d194891ed05ae.zip | |
updated Prolog solution for 241.1
Diffstat (limited to 'challenge-241')
| -rw-r--r-- | challenge-241/adam-russell/prolog/ch-1.p | 25 |
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. |
