You are not logged in. Your edit will be placed in a queue until it is peer reviewed.
We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.
- You can only move one unit at a time, so many times you have to retrace your path I thinkdavid– david2013-02-09 20:56:33 +00:00Commented Feb 9, 2013 at 20:56
- I don't really follow you.It seems that the requirement is just to move forward and swap numbers.You already know the current location and the target location.Just swap them (using the cart variable as you say it) and move to the next pairuser10326– user103262013-02-09 20:57:53 +00:00Commented Feb 9, 2013 at 20:57
- Consider this counterexample: (1, 10), (10, 1), (2, 3), (3, 4). The optimal way to do this would be to carry object 1 to position 10, then pick up the object at position 10 and carry it to position 1, then to carry the 2 to the 3 and the 3 to the 4. Doing this in sorted order of starting position would carry the 1 to the 10, then back all the way up to the start to carry the 2 to the 3, the 3 to the 4, then go all the way to the end to pick up the 10 and bring it back.templatetypedef– templatetypedef2013-02-09 20:58:17 +00:00Commented Feb 9, 2013 at 20:58
- @templatetypedef:I see what you mean.Updated answeruser10326– user103262013-02-09 21:13:56 +00:00Commented Feb 9, 2013 at 21:13
- In your updated answer, does the "current index" just indicate the current position?david– david2013-02-09 22:31:48 +00:00Commented Feb 9, 2013 at 22:31
Add a comment |
How to Edit
- Correct minor typos or mistakes
- Clarify meaning without changing it
- Add related resources or links
- Always respect the author’s intent
- Don’t use edits to reply to the author
How to Format
- create code fences with backticks ` or tildes ~ ```
like so
``` - add language identifier to highlight code ```python
def function(foo):
print(foo)
``` - put returns between paragraphs
- for linebreak add 2 spaces at end
- _italic_ or **bold**
- indent code by 4 spaces
- backtick escapes
`like _so_` - quote by placing > at start of line
- to make links (use https whenever possible) <https://example.com>[example](https://example.com)<a href="https://example.com">example</a>
How to Tag
A tag is a keyword or label that categorizes your question with other, similar questions. Choose one or more (up to 5) tags that will help answerers to find and interpret your question.
- complete the sentence: my question is about...
- use tags that describe things or concepts that are essential, not incidental to your question
- favor using existing popular tags
- read the descriptions that appear below the tag
If your question is primarily about a topic for which you can't find a tag:
- combine multiple words into single-words with hyphens (e.g. design-patterns), up to a maximum of 35 characters
- creating new tags is a privilege; if you can't yet create a tag you need, then post this question without it, then ask the community to create it for you