Hybrid Exercise

## 17.8 Hybrid Exercise

Build a hybrid algorithm to create lists whose elements all differ by at least 2. Try lists of length 3,5,7,8. To test its performance, reduce the domains thus: `ic:(List::1..TwoL-2)` so the program tries all possibilities before failing.
Use the following skeleton:

>     differ(Length,List) :-
>         length(List,Length),
>         TwoL is 2*Length,
>         ic:(List::1..TwoL-1),
>         alldiff(List,TwoL,Bools),
>         [To be completed]

>     alldiff(List,Length,Bools) :-
>         (  fromto(List,[X|Rest],Rest,[]),
>            fromto([],BIn,BOut,Bools),
>            param(Length)
>         do
>             diffeach(X,Rest,Length,BIn,BOut)
>         ).

>     diffeach(X,List,Length,BIn,BOut) :-
>             (foreach(Y,List),
>              fromto(BIn,TB,[B|TB],BOut),
>              param(X,Length)
>             do
>                 diff2(X,Y,Length,B)
>             ).

- (a) Create an IC algorithm using

  >     diff2(X,Y,_,_) :- ic: ((X+2 #=< Y) or (Y+2 #=< X)).

- (b) Create an eplex algorithm using

  >     diff2(X,Y,Max,B) :-
  >         eplex:(B::0..1),
  >         eplex:( X+2 + B*Max $=< Y+Max),
  >         eplex:(X+Max $>= Y+2 + (1-B)*Max).

- (c) Try and find the best hybrid algorithm. (NB This is, unfortunately, a trick question ;-))