subject

C CODE .Finish the code and run ./fork-puzzle |sort| uniq. Which of the following is the correct output?

//In this assignment, we use fork() to create multiple processes to solve a puzzle.

//The puzzle is specified by the following array

//int a[] = {3, 6, 4, 1, 3, 4, 2, 5, 3, 0};

//A walker walks along the index of this array.

//He starts at index 0, where a[0] is 3, which indicates that

//the walker can move 3 steps. If the walker moving to the left, he would be at index

//-3, which is out of the range. Hence, he can only move to the right, after he makes the move,//he will be at index 3. Since a[3] = 1, he can move to the left or right by one move.

//Note whenever he makes his move, he should be in the range [0, 9]. He is not allowed to move

//outside of this range.

//The goal of the puzzle is to for the walker to reach index 9, where a[9] = 0. And he will

//stop there.

//What we need to do is to find the solutions of this puzzle. We limit the solutions to have

//at most 10 moves.

#include

#include

#include

#include

void print_solution(int b[], int moves)

{

for(int k = 0; k
{

printf("->%d ", b[k]);

}

printf("\n");

}

int main(int argc, char *argv[])

{

//We use the array a to describe the puzzle

int a[] = {3, 6, 4, 1, 3, 4, 2, 5, 3, 0};

//We use the array b to save the moves the walker makes

//Essentially, we save each index that the walker reaches in array b

//For example, b[0] = 3 since the walker goes to index 3 for the first move

int b[10];

int cur = 0;

int moves = 0;

int n = 10;

for(int i = 0; i< n; i++)

{

if(fork() == 0)

{

//If we find a solution, we print the solution

if(a[cur]==0)

{

b[moves - 1] = cur;

print_solution(b, moves);

return 0;

}

else if(cur + a[cur] >= 0 && cur + a[cur]
{

//Add your code here

}

}

else

{

//If we find a solution, we print the solution

if(a[cur]==0)

{

b[moves - 1] = cur;

print_solution(b, moves);

return 0;

}

else if(cur - a[cur] >= 0 && cur - a[cur]
{

//Add your code here

}

}

}

return 0;

}

/*

Note run your code the following different ways and observe the outputs

./fork-puzzle

./fork-puzzle |sort

./fork-puzzle |sort| uniq

*/

there is four option, chose one.

->3 ->2 ->6 ->8 ->5 ->9

->3 ->4 ->1 ->7 ->2 ->6 ->8 ->5 ->9

->3 ->4 ->7 ->2 ->6 ->8 ->5 ->9

All of the above

ansver
Answers: 3

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 12:40
In a response of approximately 50 words, explain why it would be essential for the successful a/v technician to participate in additional coursework, presentations and seminars offered by equipment manufacturers as well as annual conferences attended by colleagues in the industry.
Answers: 1
question
Computers and Technology, 22.06.2019 21:50
Given int variables k and total that have already been declared, use a while loop to compute the sum of the squares of the first 50 counting numbers, and store this value in total. thus your code should put 11 + 22 + 33 + + 4949 + 50*50 into total. use no variables other than k and total.
Answers: 2
question
Computers and Technology, 24.06.2019 23:40
Which slide should you change so it reflects om all sides of your presentation
Answers: 1
question
Computers and Technology, 25.06.2019 05:00
7. the cullerton park district holds a mini-olympics each summer. create a class named participant with fields for a name, age, and street address. include a constructor that assigns parameter values to each field and a tostring() method that returns a string containing all the values. also include an equals() method that determines two participants are equal if they have the same values in all three fields. create an application with two arrays of at least eight participants each—one holds participants in the mini-marathon, and the other holds participants in the diving competition. prompt the user for participant values. after the data values are entered, display values for participants who are in both events. save the files as participant.java and twoeventparticipants.java.
Answers: 2
You know the right answer?
C CODE .Finish the code and run ./fork-puzzle |sort| uniq. Which of the following is the correct out...
Questions
question
Mathematics, 21.01.2021 23:00
question
English, 21.01.2021 23:00