Dice Game

Need some help on how to develop a function to search for consecutive identical integers in an array, and to replace those integers with double that integer.

Say for instance, the set of scores (7 8 6 6 5 6) would become (7 8 12 12 5 6).
The set of scores (6 4 4 4 8 9 5) should become (6 8 8 8 8 9 5).
Last edited on
.
Last edited on
Make one pass through the array, keeping track of two positions in the array:
the start and end positions of a set of consecutive identical integers.

When the end position is reached,
a. if there are more than one consecutive identical integers between them, double the values
b. update the start position for the next set of consecutive identical integers.

Spoiler: http://coliru.stacked-crooked.com/a/a32e5843701663a8
Topic archived. No new replies allowed.