Rocksolid Light

News from da outaworlds

mail  files  register  groups  login

Message-ID:  

Avert misunderstanding by calm, poise, and balance.


comp / comp.lang.python / Re: The "Strand" puzzle --- ( Continued Fractions using Lisp or Python? )

SubjectAuthor
* Re: The "Strand" puzzle --- ( Continued Fractions using Lisp or Python? )HenHanna
+- Re: The "Strand" puzzle --- ( Posting On Python-List Prohibited)Lawrence D'Oliveiro
`- Re: The "Strand" puzzle --- ( Continued Fractions using Lisp orPython? )B. Pym

1
Subject: Re: The "Strand" puzzle --- ( Continued Fractions using Lisp or Python? )
From: HenHanna
Newsgroups: rec.puzzles, sci.lang, sci.math, comp.lang.lisp, comp.lang.python
Organization: A noiseless patient Spider
Date: Mon, 29 Jul 2024 18:58 UTC
References: 1 2
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: HenHanna@devnull.tb (HenHanna)
Newsgroups: rec.puzzles,sci.lang,sci.math,comp.lang.lisp,comp.lang.python
Subject: Re: The "Strand" puzzle --- ( Continued Fractions using Lisp or
Python? )
Date: Mon, 29 Jul 2024 11:58:21 -0700
Organization: A noiseless patient Spider
Lines: 42
Message-ID: <v88ood$jnp6$1@dont-email.me>
References: <v7u7qd$2dgbs$1@dont-email.me>
<6f90c2b4abed28c153dea46de3af408d@www.novabbs.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Mon, 29 Jul 2024 20:58:22 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="cda7bbd820da97e0a9151b7b6d2c87f6";
logging-data="646950"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+1q4Hf2t50AvEH3WtlpAjaw5ASmsZJU9Y="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:ZoyBmh4ek+Wgc/jkRLEuhqe3t7A=
In-Reply-To: <6f90c2b4abed28c153dea46de3af408d@www.novabbs.com>
Content-Language: en-US
View all headers

On 7/26/2024 5:37 AM, IlanMayer wrote:
> On Thu, 25 Jul 2024 19:07:56 +0000, HenHanna wrote:
>
>>
>> e.g. -------- For the (street)  Numbers (1,2,3,4,5,6,7,8)
>>
>>                          (1,2,3,4,5)  and  (7,8)  both add up to 15.
>>
>>
>>
>> “In a given street of houses with consecutive numbers between 50 and
>> 500, find the house number, for which, the sum of numbers on the left is
>> equal to the sum of numbers on the right”
>>
>>
>>
>>   Ramanujan and Strand Puzzle
>>
>>             this was a very interesting puzzle tackled by the genius
>> Srinivasa Ramanujan.        In the year 1914, P.C. Mahalanobis, a Kings
>> college student in England, got hold of a puzzle from the Strand
>> magazine.
>
> Solution found at:
> https://ubpdqnmathematica.wordpress.com/2021/12/05/ramanujan-and-strand-puzzle/

thanks!

>>> 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???

Subject: Re: The "Strand" puzzle --- ( Posting On Python-List Prohibited)
From: Lawrence D'Oliv
Newsgroups: comp.lang.python
Organization: A noiseless patient Spider
Date: Mon, 29 Jul 2024 21:58 UTC
References: 1 2 3
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ldo@nz.invalid (Lawrence D'Oliveiro)
Newsgroups: comp.lang.python
Subject: Re: The "Strand" puzzle --- ( Posting On Python-List Prohibited)
Date: Mon, 29 Jul 2024 21:58:02 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 24
Message-ID: <v89399$ld7e$6@dont-email.me>
References: <v7u7qd$2dgbs$1@dont-email.me>
<6f90c2b4abed28c153dea46de3af408d@www.novabbs.com>
<v88ood$jnp6$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Mon, 29 Jul 2024 23:58:02 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="6078d3e18c99978c948f5799615335d3";
logging-data="701678"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/N6uS9egXUcxW+JVrBQAA9"
User-Agent: Pan/0.159 (Vovchansk; )
Cancel-Lock: sha1:+IwIqNHmeIv1lMMm3GOuFEE/FNc=
View all headers

On Mon, 29 Jul 2024 11:58:21 -0700, HenHanna wrote:

> ---------- is this (also) easy to do using Lisp or Python???

I threw this code together in about two minutes:

lo = 50
hi = 500
i = (lo + hi) // 2
while True :
losum = sum(range(lo, i))
hisum = sum(range(i + 1, hi + 1))
print(i, losum, hisum)
if losum == hisum :
break
if losum > hisum :
i = i - 1
else :
i = i + 1
#end if
#end while

and it seems there is no actual solution: it keeps oscillating between 355
and 356.

Subject: Re: The "Strand" puzzle --- ( Continued Fractions using Lisp orPython? )
From: B. Pym
Newsgroups: rec.puzzles, sci.lang, sci.math, comp.lang.lisp, comp.lang.python
Followup: rec.puzzles
Organization: A noiseless patient Spider
Date: Thu, 1 Aug 2024 09:33 UTC
References: 1 2 3
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Nobody447095@here-nor-there.org (B. Pym)
Newsgroups: rec.puzzles,sci.lang,sci.math,comp.lang.lisp,comp.lang.python
Subject: Re: The "Strand" puzzle --- ( Continued Fractions using Lisp orPython? )
Followup-To: rec.puzzles
Date: Thu, 1 Aug 2024 09:33:53 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 45
Message-ID: <v8fkps$23nr5$1@dont-email.me>
References: <v7u7qd$2dgbs$1@dont-email.me> <6f90c2b4abed28c153dea46de3af408d@www.novabbs.com> <v88ood$jnp6$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 01 Aug 2024 11:33:53 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="5e130b75a0a049f5f5ae85e7f8f6d757";
logging-data="2219877"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19cxGN4XMqLZZFP0GT+ekBb"
User-Agent: XanaNews/1.18.1.6
Cancel-Lock: sha1:EcElLL6qNDDBuCFI2BHvpl8UPvo=
View all headers

HenHanna wrote:

> > > e.g. -------- For the (street)  Numbers (1,2,3,4,5,6,7,8)
> > >
> > >        (1,2,3,4,5)  and  (7,8)  both add up to 15.
> > >
> > >
> > >
> > > "In a given street of houses with consecutive numbers between
> > > 50 and 500, find the house number, for which, the sum of
> > > numbers on the left is equal to the sum of numbers on the
> > > right"

Gauche Scheme

(define (strand lst)
(let go ((left-sum 0) (tail lst))
(if (null? tail)
#f
(let ((right-sum (fold + 0 (cdr tail))))
(cond ((< left-sum right-sum)
(go (+ left-sum (car tail)) (cdr tail)))
((= left-sum right-sum) (car tail))
(#t #f))))))

(strand '(1 2 3 4 5 6 7 8))
===>
6

(lrange 2 5)
===>
(2 3 4)

(any
(lambda (n)
(if (strand (lrange 50 n))
n
#f))
(lrange 500 50 -1))
===>
352

(strand (lrange 50 352))
===>
251

1

rocksolid light 0.9.8
clearnet tor