T
T
TheDailyLeo2020-02-28 06:49:30
Programming
TheDailyLeo, 2020-02-28 06:49:30

[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?

5e588da1c20a5099497400.png

Answer the question

In order to leave comments, you need to log in

3 answer(s)
X
xmoonlight, 2020-02-28
@xmoonlight

I believe that the algorithm: division into a "column" (as in a notebook, without computational means).

R
Ruslan Khakimyanov, 2020-02-28
@SlonicK

2 steps:
1. Divide by ten (shift decimal point/point)
2. Multiply by two (many ways)

S
Sumor, 2020-02-28
@Sumor

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 question

Ask a Question

731 491 924 answers to any question