aboutsummaryrefslogtreecommitdiff
path: root/challenge-277/2colours/prolog/ch-2.p
blob: 8c8a36b2207589408fcab55feadc95c8c899ea0b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
:- use_module(library(clpfd)).

find_value2(List, Index, Value, Value2) :-
        Index2 #> Index,
        nth0(Index2, List, Value2),
        (Value2 - Value >= Value, !, fail ; true).

task2(Ints, Nr_Strong_Pairs) :-
        sort(Ints, Ints_Sorted),
        findall([Value, Value2],
                (nth0(Index, Ints_Sorted, Value),
                find_value2(Ints_Sorted, Index, Value, Value2)),
                Solutions),
        length(Solutions, Nr_Strong_Pairs).