🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: Turing Machine Traces: all 10 questions

Quiz: Turing Machine Traces · Question 4 of 10

What does this print? (code)

What does this print?

add = {("q0", "1"): ("q0", "1", "R"), ("q0", "+"): ("q1", "1", "R"),
       ("q1", "1"): ("q1", "1", "R"), ("q1", "_"): ("q2", "_", "L"),
       ("q2", "1"): ("acc", "_", "L")}
cells, head, state = dict(enumerate("11+1")), 0, "q0"
while state != "acc":
    state, cells[head], move = add[(state, cells.get(head, "_"))]
    head += 1 if move == "R" else -1
print("".join(cells.values()).strip("_"))
  1. A.11+1
  2. B.1111
  3. C.111
  4. D.11
Answer & explanation

Correct answer: 111

2 + 1 = 3: the + becomes a 1 and the last 1 is erased, leaving 111.

Can you get the rest right without peeking?

Take the timed Quiz: Turing Machine Traces quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →