Re: Add the numbers in a 9x9 multiplication Table

Liste des GroupesRevenir à cl lisp 
Sujet : Re: Add the numbers in a 9x9 multiplication Table
De : 643-408-1753 (at) *nospam* kylheku.com (Kaz Kylheku)
Groupes : rec.puzzles comp.lang.lisp comp.lang.python
Date : 02. Jan 2025, 06:49:18
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <20250101214422.224@kylheku.com>
References : 1
User-Agent : slrn/pre1.0.4-9 (Linux)
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

Date Sujet#  Auteur
2 Jan 25 * Add the numbers in a 9x9 multiplication Table5HenHanna
2 Jan 25 +- Re: Add the numbers in a 9x9 multiplication Table1Kaz Kylheku
2 Jan 25 `* Re: Add the numbers in a 9x9 multiplication Table3yeti
3 Jan 25  `* Re: Add the numbers in a 9x9 multiplication Table2HenHanna
4 Jan 25   `- Re: Add the numbers in a 9x9 multiplication Table1Kaz Kylheku

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal