[Edu-sig] the importance of divmod

Andre Alexander Bell news at andre-bell.de
Thu Jan 13 11:49:58 CET 2011


Hello Michel,

On 13.01.2011 07:16, michel paul wrote:
> But then, what if we want to think about it in purely mathematical
> terms?  If we agree that, for whatever reason, we cannot convert to
> strings, how might we think about reversing digits using purely
> functional reasoning, just % and recursion?  That's how I initially
> presented it, and then a kid suggested using divmod, and I was
> delighted.  It totally simplified the expression.

You mean it simplified to something like this:

n = 0
d = 1234
while d!=0:
    d,r = divmod(d,10)
    n = n*10 + r

> I think it would be great to come up with a list of divmod math
> problems.  Anybody have some?  I think developing fluency in divmod
> sorts of reasoning would do a whole lot of good for understanding
> ratio.  Our current state of high school mathematical literacy that
> equates a rational number with some bizarre decimal is horrible.

I think that is an interesting point. Actually the Euclid Algorithm is
another good divmod example.
On the other hand you might as well argue that numbers in the given
number system should have an access method to their digits like strings
to their chars. In that case however, it would feel more natural if the
indices are reverse. Then each index directly maps to the power of the
base used. Example:

i = 1234
i[0] == 4
i[1] == 3
i[2] == 2
i[3] == 1

This would allow for

a = 0
a[3] = 1
a == 1000

Regards


Andre



More information about the Edu-sig mailing list