Interesting question: Bugs composed of 0 and 1

Source: Internet
Author: User

Question excerpt: http://www.cs.cmu.edu/puzzle/puzzle37.html

A long worm crawls into a cosmetic veterinary surgery, complaining of a problem with 1's. A worm can be thought of as a string of 0's and 1's and the most beautiful worm is 00000 ... 0. The worm is a sequence of segments and there is a 0 or a 1 on each segment. The procedure for removing 1's is complicated. If there is a 1 at the right hand end (where the tail is), then the surgeon can remove this 1 (and the segment it lies on) and place a new segment with 0 or a 1 at the left hand end (where the head is).If however there is a 0 at the right hand end then the surgeon can remove it, but he has no control over what appears on the new segment at the left hand end. Indeed, the surgeon has to operate under the assumption that there is an adversary making a choice of what to replace a 0 by.The adversary would like the operation to continue indefinitely. The surgeon claims a 100% success rate. Do you believe him?

There is a worm. its entire body consists of N segments, each of which is either defective 1 or flawless 0, therefore, the body structure of the whole worm can be represented by an N-bit 01 string. Your goal is to turn the whole bug into a perfect form of 000... 00. Each time, you can cut down the rightmost section of the worm, and the worm will grow a new section on the leftmost side to keep the total length of the worm unchanged. If you cut a worm by 1, you can specify whether the worm grows at the left to 1 or 0, but if you cut it by 0, then you cannot control what the worm will grow on the leftmost side-it may grow 0 or 1, so you have to assume that the probability will always be right with you, god will do his best to obstruct you. Our problem is: no matter what the initial state of the worm is, can you always make sure that the worm is changed to 000... 00 in a limited step?
Note that this problem may not be as simple as you think. Obviously, we have to change some 1 values to 0 so that the number of 1 values can gradually decrease and eventually disappear. However, if you simply change 1 to 0 every time, you will surely win if you don't know it. For example, if the worm is 101, remove the rightmost 1 and choose to grow a 0 on the left. The worm will change to 010. Then, remove the 0 on the Right of 010, if the left side grows 1, the whole bug returns to the 101 state. Once and again, you will never get 000. The smarter way is to change 101 to 110 first, and the next step will change the bug to 111 or. In either case, you only need to change 1 to 0 one by one to win. The use of appropriate strategies makes the problem even more interesting.
No matter what the worm looks like at the beginning, we can always win within a limited step. Here is the proof given by Peter Winkler. Let's take n consecutive operations as a round of operations, so completing a round of operations is just to update the whole body of the worm. Therefore, each round of operations is equivalent to considering every bit of a worm from right to left. You can choose whether to change it to 0 when you encounter a 1, each time a zero value is encountered, it is randomly changed to 1. We rebuild the body of a worm in one round, and adopt this strategy in each round: From the rightmost end, we change it to 0 every time we encounter 1 until 0 is changed to 1 for the first time; after that, all the 1 values remain unchanged regardless of the new 0 values. If no 0 is changed to 1 after this round, we will replace all 1 with 0 to get 000... if 0 is changed to 1 on the way, the entire bug will be strictly increased as a binary number. After each round, as long as the worm does not become 000... 00, the entire binary number will become larger, and will eventually become 111... in the form of 11, there will be no more 0 to 1 at this time, so according to our strategy, in the next round, all 1 will become 0 to win.

Problem-solving ideas from: http://www.matrix67.com/blog/archives/5063

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.