pub struct TuringTape<Alphabet> { /* private fields */ }
Expand description
A possibly theorically infinite TuringTape
Implementations§
Source§impl<Alphabet: Clone> TuringTape<Alphabet>
impl<Alphabet: Clone> TuringTape<Alphabet>
Sourcepub fn new(
empty: Alphabet,
start: Alphabet,
initial: Vec<Alphabet>,
) -> TuringTape<Alphabet>
pub fn new( empty: Alphabet, start: Alphabet, initial: Vec<Alphabet>, ) -> TuringTape<Alphabet>
Initialize a new TuringTape with:
- empty: The token put at empty tape cells
- start: The token put in the first cell
- initial: An vector of tokens to be put after the start token
Examples found in repository?
examples/divisibility.rs (line 103)
73fn main() {
74 let n = std::env::args()
75 .nth(1)
76 .expect("No first argument given. Usage: cargo run --example divisibility -- <int> <int>");
77 let k = std::env::args()
78 .nth(2)
79 .expect("No second argument given. Usage: cargo run --example divisibility -- <int> <int>");
80
81 let n = n
82 .parse::<usize>()
83 .expect("First argument is not a positive integer");
84 let k = k
85 .parse::<usize>()
86 .expect("Second argument is not a positive integer");
87
88 println!("n: {}, k: {}", n, k);
89
90 let mut ns = vec![Alphabet::One; n];
91 let mut ks = vec![Alphabet::One; k];
92
93 let mut delta = vec![Alphabet::Delta];
94
95 let mut initial = Vec::new();
96
97 initial.append(&mut delta.clone());
98 initial.append(&mut ns);
99 initial.append(&mut delta.clone());
100 initial.append(&mut ks);
101 initial.append(&mut delta);
102
103 let tape = TuringTape::new(Alphabet::Delta, Alphabet::StartToken, initial);
104 println!("Tape: {}", tape);
105
106 println!("\n\nRunning...\n\n");
107
108 use States::*;
109 let end_state = tape.run_states(Start, vec![CycleStart, InvalidSyntax, DivByNull, LeftOver]);
110
111 println!("Tape: {}", tape);
112 println!("Endstate: {:?}", end_state);
113}
Sourcepub fn get_cursor(&self) -> Alphabet
pub fn get_cursor(&self) -> Alphabet
Fetch the token at the cursor
Sourcepub fn set_cursor(&self, value: Alphabet) -> Alphabet
pub fn set_cursor(&self, value: Alphabet) -> Alphabet
Set the token at the cursor and return the old token
Sourcepub fn step_right(&self) -> Alphabet
pub fn step_right(&self) -> Alphabet
Make the cursor go one cell to the right
Sourcepub fn step_left(&self) -> Alphabet
pub fn step_left(&self) -> Alphabet
Make the cursor go one cell to the left
Will panic if one goes off the tape.
Sourcepub fn run_states<S: TuringStates<Alphabet> + PartialEq>(
&self,
start_state: S,
end_states: Vec<S>,
) -> S
pub fn run_states<S: TuringStates<Alphabet> + PartialEq>( &self, start_state: S, end_states: Vec<S>, ) -> S
Runs from start state until one of the end states has been reached. Will return the end state.
Examples found in repository?
examples/divisibility.rs (line 109)
73fn main() {
74 let n = std::env::args()
75 .nth(1)
76 .expect("No first argument given. Usage: cargo run --example divisibility -- <int> <int>");
77 let k = std::env::args()
78 .nth(2)
79 .expect("No second argument given. Usage: cargo run --example divisibility -- <int> <int>");
80
81 let n = n
82 .parse::<usize>()
83 .expect("First argument is not a positive integer");
84 let k = k
85 .parse::<usize>()
86 .expect("Second argument is not a positive integer");
87
88 println!("n: {}, k: {}", n, k);
89
90 let mut ns = vec![Alphabet::One; n];
91 let mut ks = vec![Alphabet::One; k];
92
93 let mut delta = vec![Alphabet::Delta];
94
95 let mut initial = Vec::new();
96
97 initial.append(&mut delta.clone());
98 initial.append(&mut ns);
99 initial.append(&mut delta.clone());
100 initial.append(&mut ks);
101 initial.append(&mut delta);
102
103 let tape = TuringTape::new(Alphabet::Delta, Alphabet::StartToken, initial);
104 println!("Tape: {}", tape);
105
106 println!("\n\nRunning...\n\n");
107
108 use States::*;
109 let end_state = tape.run_states(Start, vec![CycleStart, InvalidSyntax, DivByNull, LeftOver]);
110
111 println!("Tape: {}", tape);
112 println!("Endstate: {:?}", end_state);
113}
Trait Implementations§
Auto Trait Implementations§
impl<Alphabet> !Freeze for TuringTape<Alphabet>
impl<Alphabet> !RefUnwindSafe for TuringTape<Alphabet>
impl<Alphabet> !Send for TuringTape<Alphabet>
impl<Alphabet> !Sync for TuringTape<Alphabet>
impl<Alphabet> Unpin for TuringTape<Alphabet>where
Alphabet: Unpin,
impl<Alphabet> !UnwindSafe for TuringTape<Alphabet>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more