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

A Puzzle Consider the following puzzle, you have n black marbles and n white mar

ID: 653302 • Letter: A

Question

A Puzzle

Consider the following puzzle, you have n black marbles and n white marbles. The playing board consists of a line of 2n + 1 locations to place the marbles in. You start with all the black marbles at one end (say, the left), all the white marbles at the other end, and an empty space in beween.

The goal is to reverse the positions of the black and white marbles. The black marbles can move only to the right and the white marbles can move only to the left. At each move, a marble can either Move one space ahead, if that space is clear, or Jump ahead over one marble of the opposite color that is one space ahead, if the space just beyond the marble is clear.

The Solving Algorithm

push the starting position onto the stack while the stack is not empty

{ pop the stack to get the current position if the current position is the goal print the solution and exit the program

for each possible move, push the resulting configuration onto the stack

} print

Explanation / Answer

import java.util.*;

public class Puzzle{

public static void main(String[] args){

String[] arr=new String[200];

int n,,i,j,len,check=0;

System.out.println(

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