However it seemed quite easy and interesting so I decided to finish it later, here is the description of the exercise as I remember it and my solution:
Bill plays some kind of game where the score is tracked on a scorecard; in addition to simple scoring moves, he can attempt (and possibly fail) more rewarding moves that will influence the score calculation.
Bill starts with a score of 0 and cannot earn negative points.
Bill can alter his total score by:
- scoring a point (integer) - it will be added to the total score
- doubling a previous score ("X") - the previous score will be doubled before adding it to the total score. If there is no previous score, it counts as 0
- summing two previous scores ("+") - the two precedent scores will be summed together before adding the result to the total score. If there are no predecessors, it counts as 0; if there is only one predecessor, it will be added again to the total score
- failing a move ("Z") - the previous score will be ignored from the total score and its value will also not be considered for subsequent special moves. If there is no previous score, this has no effects