28
3
Introduction
The rain finally subsided. Most of humanity drowned due to a bug in @user12345's code. Survivors are scattered across a worldwide archipelago. Radio communication is up, and humanity is poised to thrive once more. For no reason whatsoever, zombie pirates have gathered at the Prime Meridian, and are sweeping westward. The horde devours all.
Problem
Our doomsday scenario can be described by 5 integers on a single line which represent a set of cooperating island communities. They are ordered from west (leftmost integer) to east (rightmost integer).
Beginning with the island farthest east, islanders flee in pairs to the next closest island. Curiously, for each pair that embarks, only one of them ever survives the trip. Islanders only travel in pairs. Odd populations elect a sole inhabitant to stay behind and provide the latest radio updates on the antics of the zombie pirate horde. Populations refuse to travel until all islands to the east of them have completed their migrations or died. When the population reaches the final, westernmost island, travel ceases.
The operations manager at the end of the world needs a program that can output the final population counts of each village.
Example Input
3 8 6 0 2
Example Output
8 1 0 1 0
Assumptions
- Input may be provided via stdin, read from an arbitrarily named file, or accepted as an argument
- For each island, 0 <= population <= 1024
- Populations never skip an island
Shortest answer wins!
When you say argument, do you mean as an argument to a function or as a command-line argument to the program? – Aleksi Torhamo – 2014-03-10T15:27:29.613
@AleksiTorhamo Command-line arg, so it wouldn't count toward your total. – Rainbolt – 2014-03-10T15:30:24.867
29I love this multi-question-spanning doomsday story. – mikhailcazi – 2014-03-10T16:23:48.160
re: "populations never skip an island" - your example does show population moving multiple islands in a row. Is there another meaning I'm missing? – Allen Gould – 2014-03-12T22:13:57.360
1@AllenGould The populations did indeed move across multiple islands, but they never skipped one. If there were 32 people on the far right island, they would die like 16, 8, 4, and finally 2 would reach the leftmost island. – Rainbolt – 2014-03-12T22:16:44.210
@Rusher - ah. Thanks for the clarification. – Allen Gould – 2014-03-12T22:24:10.140