Answer the question
In order to leave comments, you need to log in
[Turing Machine] How can a number (in decimal notation) be divided by 5?
Hello! The task sounds next. way: "Given a number in decimal notation. Divide it by 5". Honestly, I don't even know where to start. Let's say the caret starts scanning from the most significant digit. I suppose you need to start like in the picture?
Answer the question
In order to leave comments, you need to log in
I believe that the algorithm: division into a "column" (as in a notebook, without computational means).
2 steps:
1. Divide by ten (shift decimal point/point)
2. Multiply by two (many ways)
You really need to multiply by two and remove the last digit.
You can multiply from the high order, you can from the low.
Multiplying by two is algorithmically quite simple and requires a small number of states.
You need to decide what the states of the machine will mean.
Here is an approximate scheme, dividing by 5, it is also multiplying by two from the most significant digit:
Qt - Start multiplying the current digit
Qr - In the next step, just go to the right
Qrr - Next two steps, go to the right
Ql - Next step, go to the left to add one
Q1 - Adding one from overflow in previous steps
Qlast - Reached the end and remove the last digit
Qend - End
The rest of the technique is to carefully write the transitions between states. Here is part of the transitions
1 + Qt -> 2 + Qr - the current position is one, we write two instead of it and prepare to move to the next digit at the next step.
2 + Qr -> Right + Qt - move to the right to the next digit
6 + Qt -> 2 + Ql - We have an overflow, so we need to go back to the left and add one
2 + Ql -> Left + Q1 - move to the left to add one later
3 + Q1 -> 4 + Qrr - added one and plan to move two positions to the right to continue work.
4 + Qrr -> Right + Qr - move to the right to the current position (there is one move to the right to continue the algorithm)
_ + Qt -> Left + Qlast - we have reached the end of the number - move to the last digit to
overwrite 0 + Qlast -> _ + Qend - overwrite the last digit and finish the job.
Fun fact 1: 9 + Q1 is an impossible state
Fun fact 2: when the state of the machine is Qlast, it must point to 0.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question