Computers and Technology, 11.03.2020 02:13 kskfbfjfk
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
Answers: 3
Computers and Technology, 23.06.2019 06:10
The head restraint should be adjusted so that it reaches a.the top of your ears b.the base of your skull c.the top of the head
Answers: 1
Computers and Technology, 23.06.2019 22:40
22. sata3 allows for data transfer rates of 600 mb/s. explain why you would likely not be able to copy data from one hard drive to another at anywhere close to this speed. also, what could be upgraded on the computer to achieve transfer speeds closer to 600 mb/s
Answers: 1
Computers and Technology, 24.06.2019 01:30
Could you find out how im still getting an 83 percent on this in edhesive a = input("enter an animal: ") s = input ("enter a sound: ") e = "e-i-e-i-o" print ("old macdonald had a farm, " + e) print ("and on his farm he had a " + a + "," + e) print ("with a " + s + "-" + s + " here and a " + s + "-" + s + " there") print ("here a " + s+ " there a " + s) print ("everywhere a " + s + "-" + s ) print ("old macdonald had a farm, " + e)
Answers: 2
Computers and Technology, 24.06.2019 06:30
Me and category do i put them in because this is science
Answers: 1
C CODE .Finish the code and run ./fork-puzzle |sort| uniq. Which of the following is the correct out...
Mathematics, 04.02.2021 15:50
Social Studies, 04.02.2021 15:50
English, 04.02.2021 15:50
Chemistry, 04.02.2021 15:50
Chemistry, 04.02.2021 15:50
Computers and Technology, 04.02.2021 15:50
Mathematics, 04.02.2021 15:50
Chemistry, 04.02.2021 15:50
History, 04.02.2021 15:50
Mathematics, 04.02.2021 15:50
Computers and Technology, 04.02.2021 16:00
English, 04.02.2021 16:00
Physics, 04.02.2021 16:00
Social Studies, 04.02.2021 16:00