-
-
Save eggrobin/07c35a2085eec9ac87dd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Machine { | |
State { | |
state = a | |
} | |
} | |
@Machine:HAS[@State:HAS[~state[halt]]] { | |
MM_PATCH_LOOP{} | |
// Clean up the mess. | |
!MM_PATCH_LOOP{} | |
@State:HAS[~stepped[*]] { | |
stepped = false | |
} | |
@State:HAS[~left_tape[*]] { | |
left_tape = ... | |
} | |
@State:HAS[~right_tape[*]] { | |
right_tape = ... | |
} | |
@State:HAS[~symbol[*]] { | |
symbol = 0 | |
} | |
// Feed tape for one step. | |
@State:HAS[~left_tape[*,...]] { | |
@left_tape = 0,... | |
} | |
@State:HAS[~right_tape[*,...]] { | |
@right_tape = 0,... | |
} | |
// We step only once per iteration, that way the tape fed above is enough. | |
@State { | |
@stepped = false | |
} | |
// Transition table (3-state 2-symbol busy beaver). | |
@State:HAS[#symbol[0],#state[a],#stepped[false]] { | |
// Write 1, move left | |
@right_tape = #1,$right_tape$ | |
@symbol = #$left_tape[0]$ | |
@left_tape ^= /[^,]+,(.*)/$1/ | |
@state = b | |
@stepped = true | |
} | |
@State:HAS[#symbol[0],#state[b],#stepped[false]] { | |
// Write 1, move right | |
@left_tape = #1,$left_tape$ | |
@symbol = #$right_tape[0]$ | |
@right_tape ^= /[^,]+,(.*)/$1/ | |
@state = a | |
@stepped = true | |
} | |
@State:HAS[#symbol[0],#state[c],#stepped[false]] { | |
// Write 1, move right | |
@left_tape = #1,$left_tape$ | |
@symbol = #$right_tape[0]$ | |
@right_tape ^= /[^,]+,(.*)/$1/ | |
@state = b | |
@stepped = true | |
} | |
@State:HAS[#symbol[1],#state[a],#stepped[false]] { | |
// Write 1, move right | |
@left_tape = #1,$left_tape$ | |
@symbol = #$right_tape[0]$ | |
@right_tape ^= /[^,]+,(.*)/$1/ | |
@state = c | |
@stepped = true | |
} | |
@State:HAS[#symbol[1],#state[b],#stepped[false]] { | |
// Write 1, move left | |
@right_tape = #1,$right_tape$ | |
@symbol = #$left_tape[0]$ | |
@left_tape ^= /[^,]+,(.*)/$1/ | |
@state = b | |
@stepped = true | |
} | |
@State:HAS[#symbol[1],#state[c],#stepped[false]] { | |
@state = halt | |
@stepped = true | |
} | |
} | |
// Cleanup. | |
@Machine:HAS[@State:HAS[#state[halt]]] { | |
@State { | |
!stepped = delete | |
} | |
} | |
// Output: | |
// Machine { | |
// State { | |
// state = halt | |
// left_tape = 1,1,0,... | |
// right_tape = 1,1,1,0,... | |
// symbol = 1 | |
// } | |
// } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
👍