Quindi sono un po 'in ritardo, ma ho pensato di lasciarlo qui ...
Turing Machine Simulazione di un Turing Machine: 370 byte?
Qui sto usando la struttura utilizzata da Turing nella sua carta del 1936. Sto usando un simbolo = un byte, inclusi m-configs e operazioni.
╔═══════════════╦═══════╦═══════════════════╦═══════════════╗
║ m-config ║ Symbol ║ Operations ║ Final m-config ║
╠═══════════════╬═══════╬═══════════════════╬═══════════════╣
║ currentCommand ║ Any ║ L ║ currentCommand ║
║ ║ * ║ MR ║ readCommand ║
╠----------------╬--------╬---------------------╬----------------╣
║ nextCommand ║ Any ║ L ║ nextCommand ║
║ ║ * ║ E R R R P* R ║ readCommand ║
╠----------------╬--------╬---------------------╬----------------╣
║ readCommand ║ P ║ R ║ readCommandP ║
║ ║ M ║ R ║ readCommandM ║
║ ║ G ║ R ║ readCommandG ║
║ ║ E ║ R ║ MHPNone ║
╠----------------╬--------╬---------------------╬----------------╣
║ readCommandP ║ 0 ║ ║ MHP0 ║
║ ║ 1 ║ ║ MHP1 ║
║ ║ e ║ ║ MHPe ║
║ ║ x ║ ║ MHPx ║
║ ║ None ║ ║ MHPNone ║
╠----------------╬--------╬---------------------╬----------------╣
║ readCommandM ║ R ║ ║ MHMR ║
║ ║ L ║ ║ MHML ║
╠----------------╬--------╬---------------------╬----------------╣
║ readCommandG ║ 1 ║ ║ G2<1 ║
║ ║ 2 ║ ║ G2<2 ║
║ ║ 3 ║ ║ G2<3 ║
║ ║ 4 ║ ║ G2<4 ║
║ ║ 5 ║ ║ G2<5 ║
╠----------------╬--------╬---------------------╬----------------╣
║ G2<1 ║ int(1) ║ L P@ R R R P* R ║ GTS ║
║ ║ < ║ ║ G21 ║
║ ║ * ║ E L ║ G2<1 ║
║ ║ @ ║ E L ║ G2<1 ║
║ ║ Any ║ L ║ G2<1 ║
╠----------------╬--------╬---------------------╬----------------╣
║ G2<2 ║ int(2) ║ L P@ R R R P* R ║ GTS ║
║ ║ < ║ ║ G22 ║
║ ║ * ║ E L ║ G2<2 ║
║ ║ @ ║ E L ║ G2<2 ║
║ ║ Any ║ L ║ G2<2 ║
╠----------------╬--------╬---------------------╬----------------╣
║ G2<3 ║ int(3) ║ L P@ R R R P* R ║ GTS ║
║ ║ < ║ ║ G23 ║
║ ║ * ║ E L ║ G2<3 ║
║ ║ @ ║ E L ║ G2<3 ║
║ ║ Any ║ L ║ G2<3 ║
╠----------------╬--------╬---------------------╬----------------╣
║ G2<4 ║ int(4) ║ L P@ R R R P* R ║ GTS ║
║ ║ < ║ ║ G24 ║
║ ║ * ║ E L ║ G2<4 ║
║ ║ @ ║ E L ║ G2<4 ║
║ ║ Any ║ L ║ G2<4 ║
╠----------------╬--------╬---------------------╬----------------╣
║ G2<5 ║ int(5) ║ L P@ R R R P* R ║ GTS ║
║ ║ < ║ ║ G25 ║
║ ║ * ║ E L ║ G2<5 ║
║ ║ @ ║ E L ║ G2<5 ║
║ ║ Any ║ L ║ G2<5 ║
╠----------------╬--------╬---------------------╬----------------╣
║ G21 ║ int(1) ║ L P@ R ║ GTS ║
║ ║ Any ║ R ║ G21 ║
╠----------------╬--------╬---------------------╬----------------╣
║ G22 ║ int(2) ║ L P@ R ║ GTS ║
║ ║ Any ║ R ║ G22 ║
╠----------------╬--------╬---------------------╬----------------╣
║ G23 ║ int(3) ║ L P@ R ║ GTS ║
║ ║ Any ║ R ║ G23 ║
╠----------------╬--------╬---------------------╬----------------╣
║ G24 ║ int(4) ║ L P@ R ║ GTS ║
║ ║ Any ║ R ║ G24 ║
╠----------------╬--------╬---------------------╬----------------╣
║ G25 ║ int(5) ║ L P@ R ║ GTS ║
║ ║ Any ║ R ║ G25 ║
╠----------------╬--------╬---------------------╬----------------╣
║ GTS ║ ^ ║ R ║ TS ║
║ ║ Any ║ R ║ GTS ║
╠----------------╬--------╬---------------------╬----------------╣
║ TS ║ 0 ║ ║ RL0 ║
║ ║ 1 ║ ║ RL1 ║
║ ║ e ║ ║ RLe ║
║ ║ x ║ ║ RLx ║
║ ║ None ║ ║ RLNone ║
╠----------------╬--------╬---------------------╬----------------╣
║ RL0 ║ @ ║ R R ║ GTS0 ║
║ ║ Any ║ L ║ RL0 ║
╠----------------╬--------╬---------------------╬----------------╣
║ RL1 ║ @ ║ R R ║ GTS1 ║
║ ║ Any ║ L ║ RL1 ║
╠----------------╬--------╬---------------------╬----------------╣
║ RLe ║ @ ║ R R ║ GTSe ║
║ ║ Any ║ L ║ RLe ║
╠----------------╬--------╬---------------------╬----------------╣
║ RLx ║ @ ║ R R ║ GTSx ║
║ ║ Any ║ L ║ RLx ║
╠----------------╬--------╬---------------------╬----------------╣
║ RLNone ║ @ ║ R R ║ GTSNone ║
║ ║ Any ║ L ║ RLNone ║
╠----------------╬--------╬---------------------╬----------------╣
║ GTS0 ║ 0 ║ R P* R ║ readCommand ║
║ ║ Any ║ R ║ GTS0 ║
╠----------------╬--------╬---------------------╬----------------╣
║ GTS1 ║ 1 ║ R P* R ║ readCommand ║
║ ║ Any ║ R ║ GTS1 ║
╠----------------╬--------╬---------------------╬----------------╣
║ GTSe ║ e ║ R P* R ║ readCommand ║
║ ║ Any ║ R ║ GTSe ║
╠----------------╬--------╬---------------------╬----------------╣
║ GTSx ║ x ║ R P* R ║ readCommand ║
║ ║ Any ║ R ║ GTSx ║
╠----------------╬--------╬---------------------╬----------------╣
║ GTSNone ║ _ ║ R P* R ║ readCommand ║
║ ║ Any ║ R ║ GTSNone ║
╠----------------╬--------╬---------------------╬----------------╣
║ MHP0 ║ ^ ║ R ║ Print0 ║
║ ║ Any ║ R ║ MHP0 ║
╠----------------╬--------╬---------------------╬----------------╣
║ MHP1 ║ ^ ║ R ║ Print1 ║
║ ║ Any ║ R ║ MHP1 ║
╠----------------╬--------╬---------------------╬----------------╣
║ MHPe ║ ^ ║ R ║ Printe ║
║ ║ Any ║ R ║ MHPe ║
╠----------------╬--------╬---------------------╬----------------╣
║ MHPx ║ ^ ║ R ║ Printx ║
║ ║ Any ║ R ║ MHPx ║
╠----------------╬--------╬---------------------╬----------------╣
║ MHPNone ║ ^ ║ R ║ PrintNone ║
║ ║ Any ║ R ║ MHPNone ║
╠----------------╬--------╬---------------------╬----------------╣
║ MHMR ║ ^ ║ R R ║ MHR ║
║ ║ Any ║ R ║ MHMR ║
╠----------------╬--------╬---------------------╬----------------╣
║ MHML ║ ^ ║ L ║ MHL ║
║ ║ Any ║ R ║ MHML ║
╠----------------╬--------╬---------------------╬----------------╣
║ Print0 ║ ^ ║ R ║ Print0 ║
║ ║ None ║ P0 ║ nextCommand ║
║ ║ Any ║ E ║ Print0 ║
╠----------------╬--------╬---------------------╬----------------╣
║ Print1 ║ ^ ║ R ║ Print1 ║
║ ║ None ║ P1 ║ nextCommand ║
║ ║ Any ║ E ║ Print1 ║
╠----------------╬--------╬---------------------╬----------------╣
║ Printx ║ ^ ║ R ║ Printx ║
║ ║ None ║ Px ║ nextCommand ║
║ ║ Any ║ E ║ Printx ║
╠----------------╬--------╬---------------------╬----------------╣
║ Printe ║ ^ ║ R ║ Printe ║
║ ║ None ║ Pe ║ nextCommand ║
║ ║ Any ║ E ║ Printe ║
╠----------------╬--------╬---------------------╬----------------╣
║ PrintNone ║ ^ ║ R ║ PrintNone ║
║ ║ None ║ ║ nextCommand ║
║ ║ Any ║ E ║ PrintNone ║
╠----------------╬--------╬---------------------╬----------------╣
║ MHL ║ ^ ║ R R ║ MHL ║
║ ║ [ ║ ║ SBL ║
║ ║ Any ║ L P^ R R E ║ nextCommand ║
╠----------------╬--------╬---------------------╬----------------╣
║ MHR ║ ^ ║ R R ║ MHR ║
║ ║ ] ║ ║ SBR ║
║ ║ None ║ P^ L L E ║ nextCommand ║
╠----------------╬--------╬---------------------╬----------------╣
║ SBR ║ ] ║ E R R P] ║ currentCommand ║
╠----------------╬--------╬---------------------╬----------------╣
║ SBL ║ ] ║ R ║ SBLE ║
║ ║ Any ║ R ║ SBL ║
╠----------------╬--------╬---------------------╬----------------╣
║ SBLE ║ [ ║ ║ currentCommand ║
║ ║ None ║ L ║ SBLE ║
║ ║ Any ║ E R R P] L ║ SBLE ║
╚═══════════════╩═══════╩═══════════════════╩═══════════════╝
Ecco uno degli esempi di Turing dal documento sopra per la mia macchina:
['<', None, 1, '0', None, 'P', 'e', None, 'M', 'R', None, 'P', 'e', None, 'M', 'R', None, 'P', '0', None, 'M', 'R', None, 'M', 'R', None, 'P', '0', None, 'M', 'L', None, 'M', 'L', None, 'G', '2',
'1', None, 'P', 'e', None, 'M', 'R', None, 'P', 'e', None, 'M', 'R', None, 'P', '0', None, 'M', 'R', None, 'M', 'R', None, 'P', '0', None, 'M', 'L', None, 'M', 'L', None, 'G', '2',
'e', None, 'P', 'e', None, 'M', 'R', None, 'P', 'e', None, 'M', 'R', None, 'P', '0', None, 'M', 'R', None, 'M', 'R', None, 'P', '0', None, 'M', 'L', None, 'M', 'L', None, 'G', '2',
'x', None, 'P', 'e', None, 'M', 'R', None, 'P', 'e', None, 'M', 'R', None, 'P', '0', None, 'M', 'R', None, 'M', 'R', None, 'P', '0', None, 'M', 'L', None, 'M', 'L', None, 'G', '2',
'_', None, 'P', 'e', None, 'M', 'R', None, 'P', 'e', None, 'M', 'R', None, 'P', '0', None, 'M', 'R', None, 'M', 'R', None, 'P', '0', None, 'M', 'L', None, 'M', 'L', None, 'G', '2',
None, 2, '1', None, 'M', 'R', None, 'P', 'x', None, 'M', 'L', None, 'M', 'L', None, 'M', 'L', None, 'G', '2',
'0', None, 'G', '3',
None, 3, '0', None, 'M', 'R', None, 'M', 'R', None, 'G', '3',
'1', None, 'M', 'R', None, 'M', 'R', None, 'G', '3',
'_', None, 'P', '1', None, 'M', 'L', None, 'G', '4',
None, 4, 'x', None, 'E', 'E', None, 'M', 'R', None, 'G', '3',
'e', None, 'M', 'R', None, 'G', '5',
'_', None, 'M', 'L', None, 'M', 'L', None, 'G', '4',
None, 5, '0', None, 'M', 'R', None, 'M', 'R', None, 'G', '5',
'1', None, 'M', 'R', None, 'M', 'R', None, 'G', '5',
'e', None, 'M', 'R', None, 'M', 'R', None, 'G', '5',
'x', None, 'M', 'R', None, 'M', 'R', None, 'G', '5',
'_', None, 'P', '0', None, 'M', 'L', None, 'M', 'L', None, 'G', '2',
None, '[', '^', None, ']', None]
Provalo online! (Usa Python 3 come interprete) - Modifica: ho appena controllato il TIO, e non sembra funzionare davvero bene ... Provalo sul tuo computer locale e dovrebbe (si spera) dovrebbe funzionare. Lo fa sul mio.