## ← 01-31 Move Function Solution

• 2 Followers
• 18 Lines

dummy description

### Get Embed Code x Embed video Use the following code to embed this video. See our usage guide for more details on embedding. Paste this in your document somewhere (closest to the closing body tag is preferable): ```<script type="text/javascript" src='https://amara.org/embedder-iframe'></script> ``` Paste this inside your HTML body, where you want to include the widget: ```<div class="amara-embed" data-url="http://www.youtube.com/watch?v=TnFq6hufsYs" data-team="udacity"></div> ``` 5 Languages

Showing Revision 2 created 04/11/2012 by Anna Chiara Bellini.

1. Here is the solution.
2. We start with the empty list. We go through all the elements in p.
3. This is the tricky line.
4. We will construct Q element-by-element by accessing the corresponding p,
5. and p is shifted by U and if this shift exceeds the range of p on the left,
6. we apply the modulo operator with the number of states as an argument.
7. In this case, it'll be 5.
8. Now, the reason why there is a minus sign is tricky.
9. To shift the distribution to the right, U = 1,
10. we need to find in p the element 1 place to the left.
11. Rather than shifting p to the right directly,
12. what I've done is I've constructed q by searching for
13. where the robot might have come from.
14. That's of course, in hindsight, from the left.
15. Therefore, there is a minus sign over here.