Problem 59621. Beam me up, Scotty!
It's the mid 22nd century.
You, Montgomery Scott, are appointed the chief engineer of the Starship Enterprise.
The Starship is set for inter-planetary missions on the other side of the galaxy, which often involves landing on rogue planets and their satellites. Primarily, Captain James T. Kirk, First Officer Spock and a few crew members take the mantle of exploring these celestial bodies, with you assisting them in transporting to and fro and the rest of the team collecting data about such erratic locations with the advanced technology around.
The number of additional crew members is determined by various factors.
Now coming to the situation at hand -
You have figured out the (ridiculous) physics required for instantenous transportation, the only thing left is to develop an algorithm which facilitates the action.
The idea is as follows - There are many spots available for transporation from a particular location, with the explorers scattered across them in groups. Each group is to be treated as a single unit which is to be done by counting the number of people in a group and assigning the value to the starting spot of the group (from left) and leave a blank (0) at the rest of the spots.
Filled spots are denoted by 1 and empty spots are denoted by 0. A group is considered to be consecutive filled spots, with empty spots on atleast one end.
Here are some examples (which might help to demonstrate the algorithm) -
%Input
in = [1 0 1 1 1 0 0]
%Output
out = [1 0 3 0 0 0 0]
%Input
in = [1 1 1 1 1 0 0 1 1]
%Output
out = [5 0 0 0 0 0 0 2 0]
%Input
in = [0 0 1 1 1 1 0 0]
%Output
out = [0 0 4 0 0 0 0 0]
Given the instantaneous nature of transportation, iterating over the data does not seem to be the best choice.
Check the test suite for restrictions on developing the algorithm due to the bizzare conditions of the challenge.
Solution Stats
Problem Comments
Solution Comments
Show commentsProblem Recent Solvers8
Suggested Problems
-
2297 Solvers
-
276 Solvers
-
605 Solvers
-
29 Solvers
-
9740 Solvers
More from this Author31
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!