Interesting math problem

sturlamolden sturlamolden at yahoo.no
Tue Mar 18 10:10:20 EDT 2008


On 18 Mar, 00:58, Jeff Schwab <j... at schwabcenter.com> wrote:

> def make_slope(distance, parts):
>      if parts == 0:
>          return []
>
>      q, r = divmod(distance, parts)
>
>      if r and parts % r:
>          q += 1
>
>      return [q] + make_slope(distance - q, parts - 1)

Beautiful. If Python could optimize tail recursion, it would even run
fast.







More information about the Python-list mailing list