Skip to content

Instantly share code, notes, and snippets.

@eggrobin
Last active January 9, 2022 18:35
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eggrobin/07c35a2085eec9ac87dd to your computer and use it in GitHub Desktop.
Save eggrobin/07c35a2085eec9ac87dd to your computer and use it in GitHub Desktop.
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
// }
// }
@pjf
Copy link

pjf commented Mar 13, 2016

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment