Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

You are to create a Turing machine which is input two positive integers n, m and

ID: 3579238 • Letter: Y

Question

You are to create a Turing machine which is input two positive integers n, m and determines

if n is divisible by m.  

The input is coded in unary. The pair of integers in the input are separated by a 2.

You should assume that you can rely on the fact that n is bigger than m and that m is at least 2. You should assume that the Machine begins by reading

the leftmost one representing the integer n.

It does not matter what the head of the machine is reading when the machine halts; what does matter is

1. That you write y and n (write immediately after the end of the second integer) to indicate that yes there is or no there is

not divisibility.

2.   That other than the additional y or n at the end, the tape looks the same as it did when you began.

3. The algorithm should work for any positive integer n > m > 1.

I remind you that in unary coding x + 1 ones are used to code x.

You should not only present your machine but also explain why the machine does what it is supposed to do.

Explanation / Answer

1)number should beadjacent to integer then it printed the yes...follow the code behind this:

public static void minGap(int[] list) {
// initialize gap with difference of first two elements of array   
int gap = Math.abs(list[1] - list[0]);
// Start the array iteration from second element as we already have difference of first two elements.
for(int i = 2; i < list.length; i++) { //cycle through the array
// calculate the difference between two adjacent element.
int absDiff = Math.abs(list[i] - list[i-1]);
// if the difference is less then the prior minimum it becomes the new minimum.
if(gap > absDiff) {   
gap = absDiff;
}
}
System.out.println("The minimum gap between 2 adjacent values is " + gap + " ");
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote