Rocksolid Light

News from da outaworlds

mail  files  register  groups  login

Message-ID:  

BOFH excuse #7: poor power conditioning


comp / comp.lang.python / Re: Add the numbers in a 9x9 multiplication Table

SubjectAuthor
* Add the numbers in a 9x9 multiplication TableHenHanna
+- Re: Add the numbers in a 9x9 multiplication TableKaz Kylheku
`* Re: Add the numbers in a 9x9 multiplication Tableyeti
 `* Re: Add the numbers in a 9x9 multiplication TableHenHanna
  `- Re: Add the numbers in a 9x9 multiplication TableKaz Kylheku

1
Subject: Add the numbers in a 9x9 multiplication Table
From: HenHanna
Newsgroups: rec.puzzles, comp.lang.lisp, comp.lang.python
Organization: novaBBS
Date: Thu, 2 Jan 2025 04:02 UTC
Path: news.eternal-september.org!eternal-september.org!feeder3.eternal-september.org!i2pn.org!i2pn2.org!.POSTED!not-for-mail
From: HenHanna@dev.null (HenHanna)
Newsgroups: rec.puzzles,comp.lang.lisp,comp.lang.python
Subject: Add the numbers in a 9x9 multiplication Table
Date: Thu, 2 Jan 2025 04:02:31 +0000
Organization: novaBBS
Message-ID: <0b09b939cdbbe465809a7ec27e30912a@www.novabbs.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Info: i2pn2.org;
logging-data="1592508"; mail-complaints-to="usenet@i2pn2.org";
posting-account="4L8HabKtc1alsSAOmk7EUGDHKRhgGhC+6gJMfTsJB0A";
User-Agent: Rocksolid Light
X-Rslight-Site: $2y$10$VyJcZWv8vHmsbxYNJppC6eHAJdqi3CZZtBZQ0kopLrawiYGcs8Oo2
X-Face: P#KeQ)CUdd!==@fw~Ms1=,Hb`IWtb6:Mw)x3B=H1BfNC\lz?Nb&)M9}$>?'X7l;CuB}utlJ=PHsRBSG6X>dYZ$[>P]$~+`>@V6$t}hTLoQ7XC~W\>:`B3ALU]SH;d(\MEc}znW8m}-ma&yPFkJ2@KSQrz=!Y;><;6a>z6N+mt`ClCt.PAE<o+B$qjwejZSZ,w]^;vrdl24z5(pm={l,F10qRDF
X-Rslight-Posting-User: abae1fed5a82111a8790dc84735f550edb4392db
X-Spam-Checker-Version: SpamAssassin 4.0.0
View all headers

Pls give (show) me nice variations in Lisp and Python. Thanks!!!

A happy new year! ...

44 x 44 = 1936
45 x 45 = 2025 <-- one reason that Puzzle nerds are excited today.
46 x 46 = 2116

_______________________________________
The following (in Lisp (Scheme) and Python) adds
all the numbers in a 9x9 multiplication Table.
________________________________
(print (apply +
(apply append
(map (lambda (y)
(map (lambda (x) (* x y)) (iota 9 1)))
(iota 9 1)))))
______________________________________
isum=0
for y in range(1, 10):
print()
for x in range(1, 10):
print(f"{x*y:3}", end=" ")
isum += x*y
print(' Total= ', isum, '\n')
_______________________________
kuku = [i*j for i in range(1, 10) for j in range(1, 10)]
print(sum(kuku))

_________

_________

i don't see why the Python compiler doesn't
give me a STERN warning when it sees that I have this line:
sum=0

Subject: Re: Add the numbers in a 9x9 multiplication Table
From: Kaz Kylheku
Newsgroups: rec.puzzles, comp.lang.lisp, comp.lang.python
Organization: A noiseless patient Spider
Date: Thu, 2 Jan 2025 05:49 UTC
References: 1
Path: news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail
From: 643-408-1753@kylheku.com (Kaz Kylheku)
Newsgroups: rec.puzzles,comp.lang.lisp,comp.lang.python
Subject: Re: Add the numbers in a 9x9 multiplication Table
Date: Thu, 2 Jan 2025 05:49:18 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 45
Message-ID: <20250101214422.224@kylheku.com>
References: <0b09b939cdbbe465809a7ec27e30912a@www.novabbs.com>
Injection-Date: Thu, 02 Jan 2025 06:49:23 +0100 (CET)
Injection-Info: dont-email.me; posting-host="083db82202383aa73ae8305bddd678d4";
logging-data="3377365"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/VOPA8yQjzvbhhh0mF0ykkSt9xBSrdPYM="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:WEpu17uHHCechZc0cD42uNjKsL8=
View all headers

On 2025-01-02, HenHanna <HenHanna@dev.null> wrote:
> Pls give (show) me nice variations in Lisp and Python. Thanks!!!
>
>
>
> A happy new year! ...
>
> 44 x 44 = 1936
> 45 x 45 = 2025 <-- one reason that Puzzle nerds are excited today.
> 46 x 46 = 2116
>
>
> _______________________________________
> The following (in Lisp (Scheme) and Python) adds
> all the numbers in a 9x9 multiplication Table.
> ________________________________
> (print (apply +
> (apply append
> (map (lambda (y)
> (map (lambda (x) (* x y)) (iota 9 1)))
> (iota 9 1)))))
> ______________________________________
> isum=0
> for y in range(1, 10):
> print()
> for x in range(1, 10):
> print(f"{x*y:3}", end=" ")
> isum += x*y
> print(' Total= ', isum, '\n')
> _______________________________
> kuku = [i*j for i in range(1, 10) for j in range(1, 10)]
> print(sum(kuku))

This is the TXR Lisp interactive listener of TXR 297.
Quit with :quit or Ctrl-D on an empty line. Ctrl-X ? for cheatsheet.
Allow me to expand a bit more on why there is no substitute for macros.
1> (sum-each ((i 1..10) (j 1..10)) (* i j))
285
2> (sum-each-prod ((i 1..10) (j 1..10)) (* i j))
2025

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca

Subject: Re: Add the numbers in a 9x9 multiplication Table
From: yeti
Newsgroups: rec.puzzles, comp.lang.lisp, comp.lang.python
Organization: Democratic Order of Pirates International (DOPI)
Date: Thu, 2 Jan 2025 10:54 UTC
References: 1
Path: news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail
From: yeti@tilde.institute (yeti)
Newsgroups: rec.puzzles,comp.lang.lisp,comp.lang.python
Subject: Re: Add the numbers in a 9x9 multiplication Table
Date: Thu, 02 Jan 2025 11:36:02 +0042
Organization: Democratic Order of Pirates International (DOPI)
Lines: 4
Message-ID: <87seq1fpv9.fsf@tilde.institute>
References: <0b09b939cdbbe465809a7ec27e30912a@www.novabbs.com>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Date: Thu, 02 Jan 2025 11:54:14 +0100 (CET)
Injection-Info: dont-email.me; posting-host="523488a423245ac4ed6bb27c4df20782";
logging-data="3473905"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18wToIRcJ+6BHzkgEZ531HI"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)
Cancel-Lock: sha1:XkIVKxG+rPIUBJ7rVuYta+yvGWs=
sha1:1mZEvun0KoGD07dDeG8sn4EiHkY=
X-Keywords: ignore
Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwAQMAAABtzGvEAAAABlBMVEUAAAD///+l2Z/dAAAAiklEQVQY02NgoCUQOASmOJwPAElGjuQfIIrH8A9IsK3wJ0jFMcPHDUAVxywPNzCw8Dy3bD7AwMzy+Q/7AQbGvuq57QsYGI+brz+fwMDw+9re/x8YGLPcFP8/YGBccaTg4QcG5o4WBeYGBnaBngTDBJBFDvUHQBY5/G8AWXHgH9j65h9gitmBgfYAAJOqKugnjqEOAAAAAElFTkSuQmCC
X-Face: "-Nh[_Q`f/iywEEk*gL\V>5N1AB*"sDJ8;EUV=C-0Y@WB9ePs{Cw>dh=u?}LO}?T(5_L2HX
`mj:w>@KY3N6`v6Y!/<)"&OTwwj<}i=2g^/|Mp#95.z4HsbUizxbZ*4X085{X||BvThEN9wD=Q1o7"
5d3u_b|SUTt
View all headers

https://oeis.org/A000537 ?

--
I do not bite, I just want to play.

Subject: Re: Add the numbers in a 9x9 multiplication Table
From: HenHanna
Newsgroups: rec.puzzles, comp.lang.lisp, comp.lang.python
Organization: novaBBS
Date: Fri, 3 Jan 2025 21:31 UTC
References: 1 2
Path: news.eternal-september.org!eternal-september.org!feeder3.eternal-september.org!news.quux.org!news.nk.ca!rocksolid2!i2pn2.org!.POSTED!not-for-mail
From: HenHanna@dev.null (HenHanna)
Newsgroups: rec.puzzles,comp.lang.lisp,comp.lang.python
Subject: Re: Add the numbers in a 9x9 multiplication Table
Date: Fri, 3 Jan 2025 21:31:34 +0000
Organization: novaBBS
Message-ID: <441f7c9599790e4d83d9910c8d099902@www.novabbs.com>
References: <0b09b939cdbbe465809a7ec27e30912a@www.novabbs.com> <87seq1fpv9.fsf@tilde.institute>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Info: i2pn2.org;
logging-data="1872681"; mail-complaints-to="usenet@i2pn2.org";
posting-account="4L8HabKtc1alsSAOmk7EUGDHKRhgGhC+6gJMfTsJB0A";
User-Agent: Rocksolid Light
X-Face: P#KeQ)CUdd!==@fw~Ms1=,Hb`IWtb6:Mw)x3B=H1BfNC\lz?Nb&)M9}$>?'X7l;CuB}utlJ=PHsRBSG6X>dYZ$[>P]$~+`>@V6$t}hTLoQ7XC~W\>:`B3ALU]SH;d(\MEc}znW8m}-ma&yPFkJ2@KSQrz=!Y;><;6a>z6N+mt`ClCt.PAE<o+B$qjwejZSZ,w]^;vrdl24z5(pm={l,F10qRDF
X-Spam-Checker-Version: SpamAssassin 4.0.0
X-Rslight-Site: $2y$10$iyZPThG8rdDGCVdJ4bqD5eteiRHLbX6g3AOa0sI4pZKWsy.2fakWq
X-Rslight-Posting-User: abae1fed5a82111a8790dc84735f550edb4392db
View all headers

On Thu, 2 Jan 2025 10:54:02 +0000, yeti wrote:

> https://oeis.org/A000537 ?

Sum of first n cubes; or n-th triangular number squared.

0, 1, 9, 36, 100, 225, 441, 784, 1296, 2025, 3025, 4356, 6084, 8281,
11025, 14400, 18496, 23409, 29241, 36100, 44100, 53361, 64009, 76176,
90000, 105625, 123201, 142884, 164836, 189225, 216225, 246016, 278784,
314721, 354025, 396900, 443556, 494209, 549081

Thank you... It's not obvous to me why

Sum of (consecutive) cubes would be a Square number.

Subject: Re: Add the numbers in a 9x9 multiplication Table
From: Kaz Kylheku
Newsgroups: rec.puzzles, comp.lang.lisp, comp.lang.python
Organization: A noiseless patient Spider
Date: Fri, 3 Jan 2025 23:12 UTC
References: 1 2 3
Path: news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail
From: 643-408-1753@kylheku.com (Kaz Kylheku)
Newsgroups: rec.puzzles,comp.lang.lisp,comp.lang.python
Subject: Re: Add the numbers in a 9x9 multiplication Table
Date: Fri, 3 Jan 2025 23:12:18 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 151
Message-ID: <20250103135542.913@kylheku.com>
References: <0b09b939cdbbe465809a7ec27e30912a@www.novabbs.com>
<87seq1fpv9.fsf@tilde.institute>
<441f7c9599790e4d83d9910c8d099902@www.novabbs.com>
Injection-Date: Sat, 04 Jan 2025 00:12:18 +0100 (CET)
Injection-Info: dont-email.me; posting-host="682964cb358837dc929862ee6f1dc146";
logging-data="138504"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19xdzbEmnH9JGeIyASwivhN09tNxPz/5ug="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:ZFjLeqUaGfFpACuf7phu9RDyrqI=
View all headers

On 2025-01-03, HenHanna <HenHanna@dev.null> wrote:
> On Thu, 2 Jan 2025 10:54:02 +0000, yeti wrote:
>
>> https://oeis.org/A000537 ?
>
> Sum of first n cubes; or n-th triangular number squared.
>
> 0, 1, 9, 36, 100, 225, 441, 784, 1296, 2025, 3025, 4356, 6084, 8281,
> 11025, 14400, 18496, 23409, 29241, 36100, 44100, 53361, 64009, 76176,
> 90000, 105625, 123201, 142884, 164836, 189225, 216225, 246016, 278784,
> 314721, 354025, 396900, 443556, 494209, 549081
>
>
>
> Thank you... It's not obvous to me why
>
> Sum of (consecutive) cubes would be a Square number.

Base case:

1^3 is a square number.

Inductive hypothesis:

Suppose that the sums of 1^3 through n^3 are a square number.
What happens when we add (n+1)^3?

In other words:

sum{1, n, n^3} = k * k (for some positive integer k)

What are we adding to this k * k?

(n+1)^3 = n^3 + 3n^2 + 3n + 1

We have to show that adding this forumla to some k * k
produces (k + m) * (k + m) for some positive integer m.

When we take a k * k square and add m to the edges, we get
k^2 + 2km + m^2. In other words, the newly added area beyond the
original k^2 consists of two k * m quadrangles and an m^2 square.

Thus, it follows that the (n+1)^3 formula must be expressible in this
form: 2km + m^2.

Each successive cube must be adding area to a previous k*k square to
make a larger square, by adding m to the edge, which results in an new
additional area of 2km + m^2. (Of course the k and m are different
for each new cube.)

n^3 + 3n^2 + 3n + 1 = m^2 + 2km

For instance, 27 is equal to { k = 3, m = 3 } 3^2 + 2*3*3.

On in the n = 7 case, 441 going to 784 (+ 343) we have { k = 21, m = 7 }:

343 = 7*7*7 = 7*7 + 2*21*7

A pattern is emerging that m is the root of the cube; in
other words that m = n + 1. Thus:

n^3 + 3n^2 + 3n + 1 = (n+1)^2 + 2k(n + 1)

n^3 + 3n^2 + 3n + 1 = n^2 + 2n + 1 + 2k(n + 1)

Get k by itself:

n^3 + 2n^2 + 3n + 1 = 2n + 1 + 2k(n + 1)

n^3 + 2n^2 + n + 1 = 1 + 2k(n + 1)

n^3 + 2n^2 + n = 2k(n + 1)

n^3 + 2n^2 + n = 2k
------
n + 1

We need to do long polynomial division to work out this
fraction on the left:

n^2 + n
_____________________
n + 1 | n^3 + 2n^2 + n + 0
n^2 + n^2
----------
n^2 + n + 0
n^2 + n
---------
0 + 0


This is the key: the division is exact!

2k = n^2 + n = n(n + 1)

k = n(n + 1)/2

which we know is an integer!

So we know that each new cube (n+1)^3 is
expressible in the form of:

m^2 + 2km

if we identify k, m as:

m = n + 1, and
k = n(n + 1)/2 .

What we have to show is that k is the correct square value.

If k is the correct original square, then we have proved it;
because k^2 + 2m is the correct quantity to take the k square
to the k + m square.

We could use a separate, parallel induction to prove this.

Note that the formula k = n(n + 1)/2 is just the summation formula
for consecutive integers from 1 to n. We can prove that
the successive squares in the squares of these sums:
sum(1..1)^2 = 1
sum(1..2)^2 = 3^2 = 9
sum(1..3)^2 = 6^2 = 36
sum(1..4)^2 = 10^2 = 100

So it's obvious by inspection that we have the correct k formula,
and we can prove it more formally.

Conclusion:

Since we have a base case, and true inductive hypothesis, the result
holds for all n.

The key insights are that

1. the sequence values are the squares of consecutive integer sums;
i.e. the squares of successive k-s, where k = n(n+1)/2.

2. each cube value added to the previous sequence value
is expressible in the form m^2 + 2km, which has the right
shape to preserve the square property, and that with some
algebra we can identify m as m = n + 1.

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca

1

rocksolid light 0.9.8
clearnet tor