On Sat, Oct 3, 2015 at 11:55 AM, Alan Gauld <alan.ga...@btinternet.com> wrote:
> On 03/10/15 19:10, C Smith wrote:
>>>
>>> Here is my modified version which I think works as you want:
>>>
>>> def findMinDepthPath(n):
>>> if n <= 0: raise ValueError
>>> elif n==1:
>>> return 0
>>> elif n==2 or n==3:
>>> return 1
>>> else:
>>> d1 = findMinDepthPath(n-1)+1
>>> d2 = d3 = (d1+1) # initialize to higher than d1
>>>
>>> if n%3 == 0:
>>> d3 = findMinDepthPath(n/3)+1
>>> if n%2 == 0:
>>> d2 = findMinDepthPath(n/2)+1
>>>
>>> return min(d1,d2,d3)
>>>
>>>
What I meant was that the algorithm assumes that the lowest value from
one "action" (minus one, divide by 2, divide by 3) is the best
possible branch in the tree. That seems intuitively correct, but is it
necessarily so?
_______________________________________________
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor