Dutch national flag on a Turing Machine

笑着哭i 提交于 2019-12-11 10:35:40

问题


I have a sequence of characters xxxxxx (with x^k and k > 0) My goal is to transform this sentence into a dutch flag, that is to say :

xxxxx -> RRWWBB xxxx -> RWBB

with R <= W <= B

All solutions that I have found, have a very high complexity. Do you have any hint/clue to help to me build a Turing machine using only one tape and one head/cursor?


回答1:


How about dividing the task into subtasks like:

  1. Change the last X to B.
  2. Change the last X to W.
  3. Change the first X to R.
  4. Change BW to WB.

EDIT:

Here's another approach: you say you've seen algorithms that start with the colors present (out of order). So all you really need is a way to put the colors in (out of order)...



来源:https://stackoverflow.com/questions/4080769/dutch-national-flag-on-a-turing-machine

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!