## Inexact Move Function solution is incorrect.

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.

Claus
121133

accept rate: 0%

Margarita Ma...
3.7k41948

Gundega ♦♦
47.3k70190320

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!

MerseyViking
5252615

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

Gustavo A. V...
1.0k61228

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.

Emeka
51

Question text:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "Title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported

×7,522
×3,815
×181
×76
×10
×9