Path: ...!npeer.as286.net!npeer-ng0.as286.net!weretis.net!feeder8.news.weretis.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: HenHanna Newsgroups: rec.puzzles,comp.lang.lisp,sci.lang,sci.math Subject: Re: The "Strand" puzzle --- ( Continued Fractions using Lisp orPython? ) Date: Thu, 1 Aug 2024 12:47:30 -0700 Organization: A noiseless patient Spider Lines: 63 Message-ID: References: <6f90c2b4abed28c153dea46de3af408d@www.novabbs.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Date: Thu, 01 Aug 2024 21:47:33 +0200 (CEST) Injection-Info: dont-email.me; posting-host="9ea15a95b9ca9618e834905215ad3b29"; logging-data="2485003"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/deG8xSTqB2zj4naYAlVPYB1a47xgt/BE=" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:0J/2dufs5EVqZ2Ph3EIPx4XfZ6A= Content-Language: en-US In-Reply-To: Bytes: 2658 On 8/1/2024 2:33 AM, B. Pym wrote: > 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 does your Newsreader set Followup-to automatically? pls disable it. i still don't see how the prob is related to the Continued Fraction. if this Continued Fraction is written as [2,1] with a bar over 1 (?) What does [3,1] correspond to?