In: Mechanical Engineering
Design a Turing Machine to construct the function f(n) = 4 [1/4 n] + 2, (that is, 2 more than 4 times the integer part of 1/4 n) for n Element N. Do not just produce a TM, but also describe briefly how it works. There is a TM in the Cooper notes that does something similar. You may modify it to produce the required TM, or produce a machine totally independently.
import turingMachine.State;
import turingMachine.Transition;
import turingMachine.TuringMachine;
public category AcceptReject produce the machine which will
solely settle for 1's
TuringMachine atomic number 69 = new TuringMachine('q');
State[] alphabetic character = new State[3];
q[0] = tm.addState(State.INITIAL);
q[1] = tm.addState(State.FINAL);
q[2] = tm.addState(State.NORMAL);
tm.addTransition(q[0], q[0], '1', '1', Transition.RIGHT);
tm.addTransition(q[0], q[1], Transition.BLANK, Transition.BLANK,
Transition.LEFT);
tm.addTransition(q[0], q[2], '0', '0', Transition.RIGHT);
// method input 111
if(tm.process("111"))
System.out.println("Accept 111");
else
System.out.println("Reject 111");
// method input 1011
if(tm.process("1011"))
System.out.println("Accept 1011");
else
System.out.println("Reject 1011");
}
}
import java.io.FileNotFoundException;
import turingMachine.TuringMachine;
/**
* Turing Machine
*/
public category Addition {
public static void main(String[] args) {
try {
// Import addition machine
TuringMachine addition = TuringMachine.inParser("addition");
// Print addition machine
System.out.println("Machine content:");
System.out.println(addition);
// method input
addition.process("1011");
// Print the tape content once the method
System.out.println("Tape content once process '1011':");
System.out.println(addition.getTapeSnapshot());
} catch (FileNotFoundException e)
}
}