I'm working on a project for a Turning machine but having problems conceptualizing the steps.
f(x) = x^3, where x is a single digit between 0 - 9 inclusive.
Based on my understanding I am to convert the number to binary but how do I find the cube of a number in binary.
Also, how do I write the cube on the tape.
So far I'm thinking I should create a state diagram that accepts the 开发者_JAVA百科binary versions of 0-9 but what next?
I would do it like this:
- Write a copy of the number to the left of your current number
- Write another copy to the left of that
- Multiply the original number with the first copy, erasing the copy
- Multiply the result by the second copy, erasing that
You will need to write a copy and a multiply "subroutine" (using states) and jump into those by setting the right states. But I think this should be doable (if a lot of work). But probably less work than encoding all cubes from 0 to 9.
精彩评论