|
| 1 | +//Program reading subroutine, the input line must like STATE-TAPESTATE-TOWRITE-DIRECTION-NEWSTATE (0-1-0-r-0 : |
| 2 | +//when the machine is in state 0 and reads 1 in the tape it writes 0, move the head to the write and stay in the state 0 |
| 3 | +🍨 🍉 program_read 🍉 |
| 4 | +🥮 |
| 5 | + 🌰 🧅 🍉 line 🍉 , ⛈️🍫 🧅 0 🧄 🧄 |
| 6 | + 🌰 🧅 🍉 rline 🍉 , 🧇 🧅 🧈 🧅 🍉 line 🍉 🧄 🍉 - 🍉 🧄 🧄 |
| 7 | + 🌰 🧅 🍉 temp_state 🍉 🎂🥕 🧅 🥧🍓 🧅 0 , 🧈 🧅 🍉 rline 🍉 🧄 🧄 🧄 🧄 |
| 8 | + 🌰 🧅 🍉 tapestate 🍉 🎂🥕 🧅 🥧🍓 🧅 1 , 🧈 🧅 🍉 rline 🍉 🧄 🧄 🧄 🧄 |
| 9 | + 🌰 🧅 🍉 towrite 🍉 🎂🥕 🧅 🥧🍓 🧅 2 , 🧈 🧅 🍉 rline 🍉 🧄 🧄 🧄 🧄 |
| 10 | + 🌰 🧅 🍉 direction 🍉 🥧🍓 🧅 3 , 🧈 🧅 🍉 rline 🍉 🧄 🧄 🧄 |
| 11 | + 🌰 🧅 🍉 newstate 🍉 🥧🍓 🧅 4 , 🧈 🧅 🍉 rline 🍉 🧄 🧄 🧄 |
| 12 | + |
| 13 | + 🥧🫐 🧅 🧈 🧅 🍉 tapestate 🍉 🧄 , 🥧🍓 🧅 🧈 🧅 🍉 temp_state 🍉 🧄 🧈 🧅 🍉 delta0 🍉 🧄 🧄 🧈 🧅 🍉 towrite 🍉 🧄 🧄 |
| 14 | + 🥧🫐 🧅 🧈 🧅 🍉 tapestate 🍉 🧄 , 🥧🍓 🧅 🧈 🧅 🍉 temp_state 🍉 🧄 🧈 🧅 🍉 delta1 🍉 🧄 🧄 🧈 🧅 🍉 direction 🍉 🧄 🧄 |
| 15 | + 🥧🫐 🧅 🧈 🧅 🍉 tapestate 🍉 🧄 , 🥧🍓 🧅 🧈 🧅 🍉 temp_state 🍉 🧄 🧈 🧅 🍉 delta2 🍉 🧄 🧄 🧈 🧅 🍉 newstate 🍉 🧄 🧄 |
| 16 | + |
| 17 | + 🌰 🧅 🍉 i 🍉 , 🧁🍷 🧅 1 , 🧈 🧅 🍉 i 🍉 🧄 🧄 🧄 |
| 18 | + |
| 19 | + 🥠 🎂🍋 🧅 🧈 🧅 🍉 i 🍉 🧄 , 🧈 🧅 🍉 n 🍉 🧄 🧄 |
| 20 | + 🍰 🥮 |
| 21 | + 🍞 🍉 program_read 🍉 |
| 22 | + 🍪 🥖 |
| 23 | +🍪 🥖 |
| 24 | + |
| 25 | +//Step subroutine, updates the tape, head position and state of the machine |
| 26 | +🍨 🍉 step 🍉 |
| 27 | +🥮 |
| 28 | + 🥠 🍞🍎 🧅 🥮🍵🍫 🧅 🧈 🧅 🍉 state 🍉 🧄 , 🍉 H 🍉 🧄 🧄 |
| 29 | + 🍰 🥮 |
| 30 | + 🌰 🧅 🍉 current_tapestate 🍉 , 🎂🥕 🧅 🧇🇧🇪 🧅 🧈 🧅 🍉 head 🍉 🧄 , 🧈 🧅 🍉 tape 🍉 🧄 🧄 🧄 🧄 |
| 31 | + 🌰 🧅 🍉 current0 🍉 , 🥧🍓 🧅 🎂🥕 🧅 🧈 🧅 🍉 state 🍉 🧄 🧄 🧈 🧅 🍉 delta0 🍉 🧄 🧄 🧄 |
| 32 | + 🌰 🧅 🍉 current1 🍉 , 🥧🍓 🧅 🎂🥕 🧅 🧈 🧅 🍉 state 🍉 🧄 🧄 🧈 🧅 🍉 delta1 🍉 🧄 🧄 🧄 |
| 33 | + 🌰 🧅 🍉 current2 🍉 , 🥧🍓 🧅 🎂🥕 🧅 🧈 🧅 🍉 state 🍉 🧄 🧄 🧈 🧅 🍉 delta2 🍉 🧄 🧄 🧄 |
| 34 | + |
| 35 | + 🌰 🧅 🍉 towrite_steptemp 🍉 , 🥧🍓 🧅 🧈 🧅 🍉 current_tapestate 🍉 🧄 , 🧈 🧅 🍉 current0 🍉 🧄 🧄 🧄 |
| 36 | + 🌰 🧅 🍉 direction_steptemp 🍉 , 🥧🍓 🧅 🧈 🧅 🍉 current_tapestate 🍉 🧄 , 🧈 🧅 🍉 current1 🍉 🧄 🧄 🧄 |
| 37 | + 🌰 🧅 🍉 newstate_steptemp 🍉 , 🥧🍓 🧅 🧈 🧅 🍉 current_tapestate 🍉 🧄 , 🧈 🧅 🍉 current2 🍉 🧄 🧄 🧄 |
| 38 | + |
| 39 | + 🌰 🧅 🍉 arr_tape 🍉 , 🥞 🧅 🧈 🧅 🍉 tape 🍉 🧄 🧄 🧄 |
| 40 | + 🥧🫐 🧅 🧈 🧅 🍉 head 🍉 🧄 , 🧈 🧅 🍉 arr_tape 🍉 🧄 , 🥯 🧅 🧈 🧅 🍉 towrite_steptemp 🍉 🧄 🧄 🧄 |
| 41 | + 🌰 🧅 🍉 tape 🍉 , 🇨🇦🍁 🧅 🧈 🧅 🍉 arr_tape 🍉 🧄 🧄 🧄 |
| 42 | + 🌰 🧅 🍉 state 🍉 , 🧈 🧅 🍉 newstate_steptemp 🍉 🧄 🧄 |
| 43 | + |
| 44 | + 🌰 🧅 🍉 head 🍉 , 🧁🍷 🧅 -1 , 🧈 🧅 🍉 head 🍉 🧄 🧄 🧄 |
| 45 | + 🍞🍫 🧅 🍉 Step (tape,state): (%d,%d) 🍉 , 🍩 🧅 🧈 🧅 🍉 tape 🍉 🧄 , 🍉 2 🍉 , 🍉 🍉 🧄 , 🧈 🧅 🍉 state 🍉 🧄 🧄 |
| 46 | + |
| 47 | + 🥠 🥮🍵🍫 🧅 🧈 🧅 🍉 direction_steptemp 🍉 🧄 , 🍉 * 🍉 🧄 |
| 48 | + 🍰 🥮 |
| 49 | + 🌰 🧅 🍉 head 🍉 , 🧁🍷 🧅 1 , 🧈 🧅 🍉 head 🍉 🧄 🧄 🧄 |
| 50 | + 🍪 |
| 51 | + 🥠 🥮🍵🍫 🧅 🧈 🧅 🍉 direction_steptemp 🍉 🧄 , 🍉 r 🍉 🧄 |
| 52 | + 🍰 🥮 |
| 53 | + 🌰 🧅 🍉 head 🍉 , 🧁🍷 🧅 2 , 🧈 🧅 🍉 head 🍉 🧄 🧄 🧄 |
| 54 | + 🍪 🥖 |
| 55 | + 🍪 🥖 |
| 56 | +🍪 🥖 |
| 57 | + |
| 58 | +🍨 🍉 run 🍉 |
| 59 | +🥮 |
| 60 | + 🍞 🍉 step 🍉 |
| 61 | + 🥠 🍞🍎 🧅 🥮🍵🍫 🧅 🧈 🧅 🍉 state 🍉 🧄 , 🍉 H 🍉 🧄 🧄 |
| 62 | + 🍰 🥮 |
| 63 | + 🍞 🍉 run 🍉 |
| 64 | + 🍪 🥖 |
| 65 | +🍪 🥖 |
| 66 | + |
| 67 | + |
| 68 | +//Turing machine initialization |
| 69 | +//Creation of three 100 by 3 matrices to represent the transition function |
| 70 | +//Declaraton of the initial state and the tape with the head at the first bit of the input |
| 71 | +🌰 🧅 🍉 state 🍉 , 🍉 0 🍉 🧄 🥖 |
| 72 | +🥐 🧅 🍉 Please type the input tape 🍉 🧄 🥖 |
| 73 | +🌰 🧅 🍉 tape 🍉 , 🧇🍫 🧅 🧇🍫 🧅 🎂🎄 🧅 500 , 🍉 2 🍉 🧄 , ⛈️🍫 🧅 0 🧄 🧄 , 🎂🎄 🧅 500 , 🍉 2 🍉 🧄 🧄 🧄 🥖 |
| 74 | +🌰 🧅 🍉 head 🍉 , 500 🧄 🥖 |
| 75 | +🥐 🧅 🍉 Please type the number of line of the program 🍉 🧄 🥖 |
| 76 | +🌰 🧅 🍉 n 🍉 , ⛈️🍫 🧅 🧄 🧄 🥖 |
| 77 | +🌰 🧅 🍉 i 🍉 , 0 🧄 🥖 |
| 78 | +🌰 🧅 🍉 delta0 🍉 , 🥧🍋 🧅 100 , 3 , 0 🧄 🥖 |
| 79 | +🌰 🧅 🍉 delta1 🍉 , 🥧🍋 🧅 100 , 3 , 0 🧄 🥖 |
| 80 | +🌰 🧅 🍉 delta2 🍉 , 🥧🍋 🧅 100 , 3 , 0 🧄 🥖 |
| 81 | + |
| 82 | +//Reading program from STDIN |
| 83 | +🍞 🍉 program_read 🍉 🥖 |
| 84 | + |
| 85 | +//Running the machine |
| 86 | +🍞 🍉 run 🍉 🥖 |
| 87 | + |
| 88 | +//Printing output (tape), final state (which should be H), and position of the head |
| 89 | +🍞🍫 🧅 🍉 Final (tape,state,head): (%d,%d,%d) 🍉 , 🍩 🧅 🧈 🧅 🍉 tape 🍉 🧄 , 🍉 2 🍉 , 🍉 🍉 🧄 , 🧈 🧅 🍉 state 🍉 🧄 , 🧈 🧅 🍉 head 🍉 🧄 🧄 🥖 |
0 commit comments