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

Claus
121133

accept rate: 0%

retagged 28 Feb '12, 15:15

Margarita%20Manterola's gravatar image

Margarita Ma...
3.7k41948


4 Answers:

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

link

answered 26 Feb '12, 01:25

Gundega's gravatar image

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!

link

answered 24 Feb '12, 07:21

MerseyViking's gravatar image

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

link

answered 24 Feb '12, 08:22

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

Gustavo A. V...
1.0k61228

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.

link

answered 26 Feb '12, 01:19

Emeka's gravatar image

Emeka
51

Your answer
Question text:

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "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

Tags

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

Asked: 24 Feb '12, 03:29

Seen: 2,530 times

Last updated: 28 Feb '12, 15:15