|
I think the solution given in the course (the one in 'cs373_unit1_19_s_Inexact-Move-Function') is incorrect, because 'overshoot' and 'undershoot' correspond to the actual direction driven. For example, instead of p[(i-U-1) % len(p)], it should be p[(i-U-sign) % len(p)], where sign is the sign of U (i.e., sign = cmp(U, 0)). That doesn't matter if U is positive, or if pOvershoot/ pUndershoot are symmetric, of course. |
|
My initial suspicion was that the solution was right, but having just drawn a bunch of boxes, arrows, and numbers on my pad, I've come to the conclusion you're right! |
|
In this case, because pOvershoot and pUndershoot have the same probability, no matter the direction of move. For other cases in which pOvershoot and pUndershoot have different probabilities, the function has to be rewritten. :D |
|
I am thinking that there is error in that solution. However, say we have a list with 4 elements [a,b,c,d]. And say U is 1. Lets start off with index 1 of the list. So, 1-U == 0, which will pick element 'a' which is index at 0. Now, 1-U-1 == -1, which will pick element 'd' which is indexed at -1. Finally, 1-U+1 == 1. |