[Tutor] Exercise in writing a python function.
john at fouhy.net
Wed Aug 9 05:37:46 CEST 2006
On 09/08/06, Kermit Rose <kermit at polaris.net> wrote:
> def incr(mult,z,zlim,mpylist):
> # mult is a vector of exponents for the multipliers in mpylist.
> # z is a positive odd integer.
> # zlim is the upper bound critical value for the sum of ( mpylist[k] *
> mpylist[k] )
> # where kth multiplier is mpylist [k]
> # and kth multiplier index is mpylist [k]
> # function incr returns the next value of vector mult.
> # mult may be thought as a number written in a variable base.
> # mult is the least significant and matches multiplier mpylist
> # adding one to mult would mean adding 1 to mult
> # unless doing so would make sum of multiplier * index exceed zlim.
> # in that case mult is set to zero, and 1 is added to mult
> # unless doing so would make sum of multilier * index exceed zlim
> # in that case, mult and mult is set to zero,
> # and 1 is added to mult
> # unless . . .
> # mult is set to -1 to indicate that the largest possible value of mult
> has been exceeded.
> # mpylist = 2 and all other multipliers in mpylist are odd.
> # mult, the index on multiplier 2, must not equal 1. It may equal zero,
> or any integer > 1,
> # provided the zlim constraint is met.
Is there anything particular that you're stuck on?
I think I understand your function, although I'm not sure what role z
plays. Are you looking for help on how to translate the description
you've given into logic suitable for programming?
More information about the Tutor