Question
Some number of bombs sit in a linear chamber, at time 0. At time 1, the bombs explode. Each sends one piece of shrapnel to
Some number of bombs sit in a linear chamber, at time 0. At time 1, the bombs explode. Each sends one piece of shrapnel to the left and one piece of shrapnel to the right. At each successive time iteration, the pieces move at a constant speed on their due courses, passing through each other unimpeded, until all have left the chamber.! ! You are to create a NetHack-esque animation of this process. Given a String describing the initial locations of the bombs, and an Integer describing the bombs concussive power, you are to compute the locations of the pieces of shrapnel at each time iteration, terminating once all have left the chamber.! ! Your method will take as input a String bombs and an Integer force. bombs will have a "B" at each position containing a bomb, and a "." at each empty position. At time 1, the Bs disappear, sending one "<" piece of sharpnel to the left, and one ">" piece of shrapnel to the right, each moving at the constant speed force. If a "<" and ">" ever occupy the same position at the same time, they will be collectively represented by a single "X".! ! Your method will return an array of Strings in which each successive element shows the occupied locations at each time unit. The rst element should show the initial locations of the bombs, using "B" and "." characters. The last element should show the empty chamber at the rst time that it becomes empty.! ! (Please see the examples on the following page if this is unclear it helps to see it in motion.)! ! Your method signature should conform to your chosen languages variant of:! ! public String[] explode(String bombs, int force) ! explode should accept its input under the following constraints: bombs should contain between 1 and 50 characters, inclusive.! Each character in bombs should be either a "." or a B.! force should be between 1 and 10, inclusive
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started