"indigs" as a topic for intro to python

kirby urner <[email protected]> Mon, 26 Aug 2024 08:01:25 -0700
Newsgroups gmane.comp.python.education
Message-ID <CAPJgG3RDugMWWXg2gmue74T1mQnjFj0h637Y=f18eUDa4HJ7kQ@mail.gmail.com>
--===============3345804669639631391==
Content-Type: multipart/alternative; boundary="000000000000d170a8062097663e"

--000000000000d170a8062097663e
Content-Type: text/plain; charset="UTF-8"

I encourage Pythonistas into teaching Python in the context of generic
computer science and mathematics, high school and above (and below for the
precocious) to consider "indigs" an accessible example of recursion at
work.

I'm testing it out in a warm up section students might visit if feeling
shaky on their Python, or just wanting more background reading.

https://github.com/4dsolutions/clarusway_data_analysis/blob/main/python_warm_up/warmup_recursion.ipynb

The idea of an indig is very simple and inherits from numerology, a kind of
primordial NLP:

Take any positive integer, split it into individual digits, add those
digits, if the sum is a single digit you're done, otherwise: repeat.

Examples:

32986513 = 3+2+9+8+6+5+1+3 = 37 = 3+7 = 10 = 1+0 = 1

59865279171 = 5+9 = 14+8 = 22+6 = 28+5 = 33+2 = 35+7 = 42+9 = 51+1 = 52+7 =
59+1 = 60 = 6+0 = 6

I got it down to this, but it's no crime to take a few more lines.

def indig(n: int):
    return n if len(str(n))==1 else indig(sum(map(int, list(str(n)))))

It's not important that "taking the indig of a number" be considered
"meaningful" in any way.  What's useful about it is it introduces type
conversion (int to string digits, back to single ints for summing) as well
as recursion.

This idea and algorithm may well have been proposed and used before in the
literature.  Sounds Martin Gardnery.  Maybe it's in Knuth already. I'm not
trying to establish priority for anything, only circling what looks like
promising pedagogy going forward and sharing it with peers.

Kirby

--000000000000d170a8062097663e
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><font face=3D"verdana, sans-serif"><br>I encourage Pythoni=
stas into teaching Python in the context of generic computer science and ma=
thematics, high school and above (and below for the precocious) to consider=
 &quot;indigs&quot; an accessible example of recursion at work. <br><br>I&#=
39;m testing it out in a warm up section students might visit if feeling sh=
aky on their Python, or just wanting more background reading.<br><br><a hre=
f=3D"https://github.com/4dsolutions/clarusway_data_analysis/blob/main/pytho=
n_warm_up/warmup_recursion.ipynb">https://github.com/4dsolutions/clarusway_=
data_analysis/blob/main/python_warm_up/warmup_recursion.ipynb</a><br><br>Th=
e idea of an indig is very simple and inherits from numerology, a kind of p=
rimordial NLP:<br><br>Take any positive integer, split it into individual d=
igits, add those digits, if the sum is a single digit you&#39;re done, othe=
rwise: repeat.<br><br>Examples:<br><br>32986513 =3D 3+2+9+8+6+5+1+3 =3D 37 =
=3D 3+7 =3D 10 =3D 1+0 =3D 1<br><br>59865279171 =3D 5+9 =3D 14+8 =3D 22+6 =
=3D 28+5 =3D 33+2 =3D 35+7 =3D 42+9 =3D 51+1 =3D 52+7 =3D 59+1 =3D 60 =3D 6=
+0 =3D 6<br><br>I got it down to this, but it&#39;s no crime to take a few =
more lines.<br><br>def indig(n: int):<br>=C2=A0 =C2=A0 return n if len(str(=
n))=3D=3D1 else indig(sum(map(int, list(str(n)))))<br><br>It&#39;s not impo=
rtant that &quot;taking the indig of a number&quot; be considered &quot;mea=
ningful&quot; in any way.=C2=A0 What&#39;s useful about it is it introduces=
 type conversion (int to string digits, back to single ints for summing) as=
 well as recursion.<br><br>This idea and algorithm may well have been propo=
sed and used before in the literature.=C2=A0 Sounds Martin Gardnery.=C2=A0 =
Maybe it&#39;s in Knuth already.<span class=3D"gmail_default" style=3D"font=
-family:verdana,sans-serif;font-size:small"> I&#39;m not trying to establis=
h priority for anything, only circling what looks like promising pedagogy g=
oing forward and sharing it with peers.</span><br><br>Kirby</font><div clas=
s=3D"gmail_default" style=3D"font-family:verdana,sans-serif;font-size:small=
"><br></div></div>

--000000000000d170a8062097663e--

--===============3345804669639631391==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
Edu-sig mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/edu-sig.python.org/
Member address: [email protected]

--===============3345804669639631391==--