-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hi,
When doing some Scheme exercises past week, an exercise resisted to my
(potential) sagacity. It is asked to write a `lagrange' function, taking
as only argument a natural number n, and which returns the list of all the
4-uples of natural integers (a, b, c, d) such that a^2+b^2+c^2+d^2=n.
The order in which the quadruples are enumerated has no sort of
importance.
I immediately thought about the two following particular cases:
* if one of the monomials squared equals n, all the others can be set
to 0,
* for n=0, we have ((0 0 0 0)) (trivial case).
However, I'm stuck when trying to link (lagrange n) to (lagrange (+ n
1)): the recursive step. Does somebody have any idea about this?
Here is an example:
(lagrange 13) ==>
((3 2 0 0) (3 0 2 0) (3 0 0 2) (2 3 0 0) (2 2 2 1) (2 2 1 2) (2 1 2 2)
(2 0 3 0) (2 0 0 3) (1 2 2 2) (0 3 2 0) (0 3 0 2) (0 2 3 0) (0 2 0 3)
(0 0 3 2) (0 0 2 3))
Thanks.
- --
Merciadri Luca
See
http://www.student.montefiore.ulg.ac.be/~merciadri/
- --
Education is the best provision for the journey to old age. (Aristotle)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Processed by Mailcrypt 3.5.8 <
http://mailcrypt.sourceforge.net/>
iEYEARECAAYFAk+USv4ACgkQM0LLzLt8MhyFYQCdG2f9o6X8doNXPZnVP47DONjA
88kAnRmZD2jqPN415NeadWqVSQmSzQCF
=WkoI
-----END PGP SIGNATURE-----