Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Christmas Riddle, Open Ended

41 views
Skip to first unread message

burs...@gmail.com

unread,
Nov 29, 2016, 3:37:19 PM11/29/16
to
How would you solve this in Prolog or CLP(FD):

One solution?
x^2 + y^2 = 1997*(x − y)

Infinitely many solutions?
x^3 + y^3 + z^3 + t^3 = 1999

One solution?
x^2 +3*x*y +2*2003*(x+y)+2003^2 = 0

Infinitely many solutions?
x^4 + y^4 + z^4 = 2002^w

Whats your favorite riddle
with your *birthday* in it?

BTW: I don't know how Prolog in simple way could be helpful
in the infinitely many solutions questions. Any Ideas?

Credits:
http://www-bcf.usc.edu/~lototsky/PiMuEp/PutnamAndBeyond-Andreescu.pdf

Barb Knox

unread,
Dec 1, 2016, 1:46:56 PM12/1/16
to
On 30/11/2016 09:37, burs...@gmail.com wrote:
> How would you solve this in Prolog or CLP(FD):
>
> One solution?
> x^2 + y^2 = 1997*(x − y)

?- [X,Y] ins -4000..4000, X^2 + Y^2 #= 1997*(X - Y), label([X,Y]).
X = -145, Y = -1827 ;
X = -145, Y = -170 ;
X = 0, Y = -1997 ;
X = Y, Y = 0 ;
X = 170, Y = -2142 ;
X = 170, Y = 145 ;
X = 1827, Y = -2142 ;
X = 1827, Y = 145 ;
X = 1997, Y = -1997 ;
X = 1997, Y = 0 ;
X = 2142, Y = -1827 ;
X = 2142, Y = -170 ;
false.


> Infinitely many solutions?
> x^3 + y^3 + z^3 + t^3 = 1999
>
> One solution?
> x^2 +3*x*y +2*2003*(x+y)+2003^2 = 0
>
> Infinitely many solutions?
> x^4 + y^4 + z^4 = 2002^w
>
> Whats your favorite riddle
> with your *birthday* in it?
>
> BTW: I don't know how Prolog in simple way could be helpful
> in the infinitely many solutions questions. Any Ideas?
>
> Credits:
> http://www-bcf.usc.edu/~lototsky/PiMuEp/PutnamAndBeyond-Andreescu.pdf
>


--
---------------------------
| BBB b \ Barbara at LivingHistory stop co stop uk
| B B aa rrr b |
| BBB a a r bbb | ,008015L080180,022036,029037
| B B a a r b b | ,047045,L014114L4.
| BBB aa a r bbb |
-----------------------------

burs...@gmail.com

unread,
Dec 5, 2016, 12:54:01 PM12/5/16
to
Am Donnerstag, 1. Dezember 2016 19:46:56 UTC+1 schrieb Barb Knox:
> > One solution?
> > x^2 + y^2 = 1997*(x − y)
>
> ?- [X,Y] ins -4000..4000, X^2 + Y^2 #= 1997*(X - Y), label([X,Y]).
> X = -145, Y = -1827 ;
> X = -145, Y = -170 ;
> X = 0, Y = -1997 ;
> X = Y, Y = 0 ;
> X = 170, Y = -2142 ;
> X = 170, Y = 145 ;
> X = 1827, Y = -2142 ;
> X = 1827, Y = 145 ;
> X = 1997, Y = -1997 ;
> X = 1997, Y = 0 ;
> X = 2142, Y = -1827 ;
> X = 2142, Y = -170 ;
> false.

My bad. The original PDF says:
"Solve the following equation in positive integers:"

Probably this means asking for:
"Is there a infinite number of them. if yes, is there
a systematic way to generated them, like it is for
example the case for pythagorean tripples?"

kint...@gmail.com

unread,
Dec 7, 2016, 11:42:37 AM12/7/16
to
~~~
#!/usr/bin/swipl -q -l

/*
<blockquote data-author="j4n bUrse">

> BTW: I don't know how Prolog in simple way could be helpful
> in the infinitely many solutions questions. Any Ideas?
>
> Infinitely many solutions?
> x^3 + y^3 + z^3 + t^3 = 1999

</blockquote data-author="j4n bUrse">
*/

/*
<script type="text/prolog/query">
?-
puzzle(many,_solution_)
.
_solution_ = {X:0.4857528537031353, Y:0.5784937057968547, Z:0.2711112521530397, T:12.596420964142569} ;
_solution_ = {X:0.05338919807400008, Y:0.3923225707200642, Z:0.7785678584614887, T:12.595991670020199} ;
_solution_ = {X:0.12786317532006786, Y:0.5067540797430516, Z:0.6967850849297843, T:12.59612184233531} ;
_solution_ = {X:0.1661774063607877, Y:0.579996202045895, Z:0.4690872627208347, T:12.596473951516383} ;
_solution_ = {X:0.9102209156138672, Y:0.43899266156495764, Z:0.1625833805831681, T:12.59533921458041} ;
_solution_ = {X:0.18104391694875624, Y:0.9522403920732666, Z:0.8978693022933745, T:12.593762714774774} .

?-
</script type="text/prolog/query">
*/

:- true
, set_prolog_flag(var_prefix,true)
, style_check(-singleton)
.

:- true
, use_module(library(clpr))
, use_module(library(clpfd))
.

puzzle(many,_solution_)
:- true
, puzzle(once,_solution_)
.

puzzle(many,_solution_)
:- true
, puzzle(many,_solution_)
.

puzzle(once,_solution_)
:- true
, _solution_={X:_X_,Y:_Y_,Z:_Z_,T:_T_}
, clpr:{pow(_X_,3) + pow(_Y_,3) + pow(_Z_,3) + pow(_T_,3) = 1999.0}
, random(_X_)
, random(_Y_)
, random(_Z_)
%, random(_T_)%_T_ IS NOT random , it is calculated above
.

~~~
kintalken
~~~

kint...@gmail.com

unread,
Dec 7, 2016, 11:46:38 AM12/7/16
to
~~~
/*
an addition to the puzzle script
that provides opportunity to make
a list of solution
*/

/*
<script type="text/prolog/query">
?-
puzzle(list,7,_solutionz_)
.
_solutionz_ = [{X:0.25981192897362965, Y:0.019894355932532033, Z:0.5982874610961902, T:12.596623556756295}, {X:0.8863074696576477, Y:0.01295705176770758, Z:0.38922835820640816, T:12.595523730001984}, {X:0.7461932764795882, Y:0.12364955304422516, Z:0.5021429194544775, T:12.595967492020305}, {X:0.8382378829859348, Y:0.3389868983865552, Z:0.0985224994664047, T:12.59578911149325}, {X:0.7826710673417634, Y:0.2835821621281403, ... : ..., ... : ...}, {X:0.6176058483799298, ... : ..., ..., ...}, {... : ..., ..., ...}] ;
false.

?-
</script type="text/prolog/query">
*/


puzzle(list,_count_,_solutionz_)
% produce a list of solutions to the puzzle .
% _count_ is any number .
% _solutionz_ is a list of solution with length is _count_ .
:- true
, [] = _solutionz_0_
, _solutionz_ = _solutionz_9_
, puzzle(each,_count_,_solutionz_0_,_solutionz_9_)
.

puzzle(each,_count_,_solutionz_0_,_solutionz_9_)
:- true
% only consider this alternative if there IS NOT SOME _count_ remaining .
% when this happens a new solution IS NOT appended to the incoming list .
% instead the outgoing list "_solutionz_9_"
% is the same as the incoming list "_solutionz_0_" .
, \+ _count_ > 0
, _solutionz_0_ = _solutionz_9_
, true
.

puzzle(each,_count_,_solutionz_0_,_solutionz_9_)
:- true
% only consider this alternative if there IS SOME _count_ remaining .
% when this happens a new solution IS appended to the incoming list .
, _count_ > 0
% the incoming list , with the new solution appended , is the outgoing list
, append(_solutionz_0_,[_solution_],_solutionz_1_)
% solve the puzzle once .
, puzzle(once,_solution_)
% recursively invoke this predicate to get another solution .
, _count_ - 1 #= _count_1_
, puzzle(each,_count_1_,_solutionz_1_,_solutionz_9_)
.

~~~
kintalken
~~~

burs...@gmail.com

unread,
Dec 7, 2016, 11:53:41 AM12/7/16
to
Am Mittwoch, 7. Dezember 2016 17:42:37 UTC+1 schrieb kint...@gmail.com:

> > Infinitely many solutions?
> > x^3 + y^3 + z^3 + t^3 = 1999
> _solution_ = {X:0.4857528537031353, Y:0.5784937057968547,
> Z:0.2711112521530397, T:12.596420964142569} ;

Nope, check the PDF, integer solutions of course.
The riddles are all from section "5.3 Diophantine Equations"

https://en.wikipedia.org/wiki/Diophantine_equation

kint...@gmail.com

unread,
Dec 7, 2016, 12:04:40 PM12/7/16
to
~~~
<blockquote data-author="kintalken">
> > > Infinitely many solutions?
> > > x^3 + y^3 + z^3 + t^3 = 1999
> > _solution_ = {X:0.4857528537031353, Y:0.5784937057968547,
> > Z:0.2711112521530397, T:12.596420964142569} ;
</blockquote data-author="kintalken">

<blockquote data-author="j4n buR53">
> Nope, check the PDF, integer solutions of course.
> The riddles are all from section "5.3 Diophantine Equations"
>
> https://en.wikipedia.org/wiki/Diophantine_equation
</blockquote data-author="j4n buR53">

The puzzle was only interesting to me if it produced an infinite number of solutions .
i.e. "I don't know how Prolog in simple way could be helpful
in the infinitely many solutions questions. Any Ideas? "

BTW , if there an infinite number of solutions , does that guarantee (mathematically) that there will be an infinite number of duplicate solutions ?

~~~
kintalken
~~~

Harry Stoteles

unread,
Dec 7, 2016, 2:09:54 PM12/7/16
to
> The puzzle was only interesting to me
> if it produced an infinite number of solutions .

On the real line this is trivial. With machine numbers
that approximate the real line, you can do it as follows:

?- T is (1999 - X**3 - Y**3 - Z**3)**(1/3).

But on the integer line?
Are there infinitely many?

For example this one using symmetry breaking
via (#=<)/2 doesnt show me unnecessary
permutations, albeit its a little slow:

Welcome to SWI-Prolog (Multi-threaded, 64 bits, Version 7.3.25-3-gc3a87c2)
Copyright (c) 1990-2016 University of Amsterdam, VU Amsterdam

?- use_module(library(clpfd)).
true.

?- [X,Y,Z,T] ins -40..40, X^3+Y^3+Z^3+T^3 #= 1999,
X #=< Y, Y #=< Z, Z #=< T, label([X,Y,Z,T]),
write([X,Y,Z,T]), nl, fail; true.
[-39,27,27,28]
[-35,-30,33,33]
[-30,-22,7,34]
[-28,-18,-2,31]
[-25,-23,0,31]
[-23,-2,17,21]
[-23,-1,7,24]
[-21,-8,17,19]
[-20,-20,18,23]
[-18,-8,7,20]
[-15,-15,-8,21]
[-9,-2,-2,14]
[-9,0,10,12]
[-5,4,9,11]
[-4,-2,7,12]
[-1,0,10,10]
true.

But does it go on and on? I am too lazy
to figure this out.
0 new messages