Re: The "Strand" puzzle --- ( Continued Fractions using Lisp or Python? )

Liste des GroupesRevenir à r puzzles 
Sujet : Re: The "Strand" puzzle --- ( Continued Fractions using Lisp or Python? )
De : pc+usenet (at) *nospam* asdf.org (Phil Carmody)
Groupes : rec.puzzles
Date : 20. Aug 2024, 22:30:57
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <8734mzj5ry.fsf@fatphil.org>
References : 1 2 3 4
User-Agent : Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux)
ilan_no_spew@hotmail.com (IlanMayer) writes:
On Mon, 29 Jul 2024 18:58:21 +0000, HenHanna wrote:
On 7/26/2024 5:37 AM, IlanMayer wrote:
   So the solutions to the Strand puzzle can be found from the
continued fraction of \sqrt{2}, which  _is_  satisfying simple.
  Using Mathematica to look at the first 10 convergents
>
---------- is this (also) easy to do using Lisp or Python???
>
This can be done with Python:
>
N = 10
a = 1
b = 1
print(str(a) + "/" + str(b))
for n in range(N):
   temp = a + 2 * b
   b = a + b
   a = temp
   print(str(a) + "/" + str(b))

Let's play golf!

There's no need for temp:

b = b + a
a = 2 * b - a

Pre:
$ perl -e '$a=1;$b=1;$n=0;while($n++<10){print("$a/$b\n");$t=$a+2*$b;$b=$a+$b;$a=$t;}'
1/1
3/2
7/5
17/12
41/29
99/70
239/169
577/408
1393/985
3363/2378

Post:
$ perl -e '$a=1;$b=1;$n=0;while($n++<10){print("$a/$b\n");$b+=$a;$a=2*$b-$a;}'
1/1
3/2
7/5
17/12
41/29
99/70
239/169
577/408
1393/985
3363/2378

Phil
--
We are no longer hunters and nomads. No longer awed and frightened, as we have
gained some understanding of the world in which we live. As such, we can cast
aside childish remnants from the dawn of our civilization.
-- NotSanguine on SoylentNews, after Eugen Weber in /The Western Tradition/

Date Sujet#  Auteur
25 Jul 24 * The "Strand" puzzle14HenHanna
26 Jul 24 `* Re: The "Strand" puzzle13IlanMayer
29 Jul 24  `* Re: The "Strand" puzzle --- ( Continued Fractions using Lisp or Python? )12HenHanna
30 Jul 24   +* Re: The "Strand" puzzle --- ( Continued Fractions using Lisp or Python? )3IlanMayer
31 Jul 24   i+- Re: The "Strand" puzzle --- ( Continued Fractions using Lisp or Python? )1HenHanna
20 Aug 24   i`- Re: The "Strand" puzzle --- ( Continued Fractions using Lisp or Python? )1Phil Carmody
1 Aug 24   `* Re: The "Strand" puzzle --- ( Continued Fractions using Lisp orPython? )8B. Pym
1 Aug 24    +* Re: The "Strand" puzzle --- ( Continued Fractions using Lisp orPython? )2HenHanna
1 Aug 24    i`- Re: The "Strand" puzzle --- ( Continued Fractions using Lisp orPython? )1Moebius
2 Aug 24    +* Re: The "Strand" puzzle --- ( Continued Fractions using Lisp orPython? )3B. Pym
2 Aug 24    i`* Re: The "Strand" puzzle --- ( Continued Fractions using Lisp orPython? )2Doc O'Leary ,
2 Aug 24    i `- Re: The "Strand" puzzle --- ( Continued Fractions using Lisp orPython? )1Doc O'Leary ,
2 Aug 24    +- Re: The "Strand" puzzle --- ( Continued Fractions using Lisp orPython? )1B. Pym
4 Aug 24    `- Re: The "Strand" puzzle --- ( Continued Fractions using Lisp orPython? )1B. Pym

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal