# Re: [eclipse-clp-users] 7.11 puzzle

From: Mark Wallace <mark.wallace_at_...269...>
Date: Tue, 13 Sep 2011 11:06:45 +1000
```Hi Joachim,
As an alternative to your improvement, you can use symmetry-breaking,
as below.  This took 3 seconds on my desktop.
(LDSB stands for "Lightweight Dynamic Symmetry Breaking")
Cheers
Mark

:- lib(ic).
:- lib(ldsb).

solve :-
Sum = 711,
Product = 711,
Prices = [A, B, C, D],
A #> 0, B #> 0, C #> 0, D #> 0,
A + B + C + D #= Sum,
A * B * C * D #= Product * 1000000,
ldsb_initialise([](A,B,C,D), [variables_interchange]),
search(Prices, 0, input_order, ldsb_indomain, complete, []),
writeln(Prices).

On 13 September 2011 10:00, Joachim Schimpf <jschimpf@...311...> wrote:

> Sergey Dymchenko wrote:
> > Hi!
> >
> > I'm trying to solve this puzzle:
> http://programmingpraxis.com/2009/11/27/7-11/
> >
> > Here is my very straightforward code:
> >
> > :- lib(ic).
> > solve :-
> >     Sum = 711,
> >     Product = 711,
> >     Prices = [A, B, C, D],
> >     A #> 0, B #> 0, C #> 0, D #> 0,
> >     A + B + C + D #= Sum,
> >     A * B * C * D #= Product * 1000000,
> >     labeling(Prices),
> >     writeln(Prices).
> >
> > It works, but it's too slow.
> > Is there any way to speed it up without being too clever and
> > explicitly say to ECLiPSe that the prices of the four items must come
> > from the list of divisors of 711?
>
> It is much faster (1.8 instead of 63 seconds on my machine) if you use
> domain splitting during search, i.e. replace labeling(Prices) with
>
>    search(Prices, 0, input_order, indomain_split, complete, [])
>
> This is probably always a good idea with relatively large domains
> and convex constraints.
>
> Other improvements?
>
>
> Cheers,
> Joachim
>
>
> ------------------------------------------------------------------------------
> BlackBerry&reg; DevCon Americas, Oct. 18-20, San Francisco, CA
> BlackBerry&reg; mobile platform with sessions, labs & more.
> See new tools and technologies. Register for BlackBerry&reg; DevCon today!
> http://p.sf.net/sfu/rim-devcon-copy1
> _______________________________________________
> ECLiPSe-CLP-Users mailing list
> ECLiPSe-CLP-Users_at_lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/eclipse-clp-users
>

--
Professor Mark Wallace
Faculty of Information Technology
Monash University
Building H, Caulfield, Vic 3145
(03) 9903 4276
```
Received on Tue Sep 13 2011 - 01:06:53 CEST

This archive was generated by hypermail 2.2.0 : Mon Jul 09 2018 - 02:05:29 CEST