turing-machine-viz icon indicating copy to clipboard operation
turing-machine-viz copied to clipboard

Reading the whole tape

Open patrikfejda opened this issue 3 years ago • 1 comments

Is there some workaround to read the whole tape once the machine run is done (e.g. console log or anything)

Lets run the following unary (11=2, 111=3, 1111=4) calculator A+B:

input: '111111$1111#'
blank: ' '
start state: look_for_1
table:
  look_for_1:
    '$': R
    1: {write: 'X', R: write_1}
  write_1:
    [1, $, '#']: R
    ' ': {write: '1', L: go_to_very_left}
  go_to_very_left:
    ['#', 1, $]: L
    'X': {R: look_for_1}

there is no way we can read what is behind the end: image

Any idea pls as a workaround for now ?

Maybe this issue would be worth consideration and some proper fix.

Thanks :)

patrikfejda avatar Apr 06 '22 11:04 patrikfejda

Agreed, it would be useful for longer inputs and outputs. I'm not working on it actively, but let me know if you come up with a workable design in your fork.

In the meantime, this will show the tape as a string in the JS console with a magnifying glass to the left of the tape head:

main.controller.simulator.machine.machine.tape.tape.toString()
'XXXXXX$XXXX🔎#1111111111'

To get an array rather than a string, you can filter and split the string, or concatenate the before and after arrays similar to what Tape.toString() does:

t = main.controller.simulator.machine.machine.tape.tape; t.before.concat(t.after.slice().reverse())
['X', 'X', 'X', 'X', 'X', 'X', '$', 'X', 'X', 'X', 'X', '#', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1']

aepsilon avatar Apr 07 '22 07:04 aepsilon