Discussion:
The "Strand" puzzle --- ( Continued Fractions using Lisp or Python? )
(too old to reply)
HenHanna
2024-07-29 18:58:21 UTC
Permalink
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.
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???
Lawrence D'Oliveiro
2024-07-29 21:58:02 UTC
Permalink
Post by HenHanna
---------- 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.
B. Pym
2024-08-01 09:33:53 UTC
Permalink
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

Loading...