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.

asked 24 Feb '12, 03:29

Claus's gravatar image


accept rate: 0%

retagged 28 Feb '12, 15:15

Margarita%20Manterola's gravatar image

Margarita Ma...

4 Answers:

There was a nice post about this problem here - my-2-on-overshoot-undershoot


answered 26 Feb '12, 01:25

Gundega's gravatar image

Gundega ♦♦

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!


answered 24 Feb '12, 07:21

MerseyViking's gravatar image


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


answered 24 Feb '12, 08:22

Gustavo%20A.%20Velasco%20Hdez's gravatar image

Gustavo A. V...

edited 24 Feb '12, 08:23

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.


answered 26 Feb '12, 01:19

Emeka's gravatar image


Your answer
Question text:

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text]( "Title")
  • 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



Asked: 24 Feb '12, 03:29

Seen: 3,461 times

Last updated: 28 Feb '12, 15:15