cards lies on the table. Until no cards are left, repeat:
- if there are at least two cards, take the leftmost and the rightmost, write the digits of the right one after the digits of the left one (so 15 and 49 make 1549), and add that number to the score;
- if a single card remains, add its number to the score.
Cards that are taken leave the table. The score starts at zero. Return the final score.cards=[3, 40, 6, 21] → 727
First the outer cards 3 and 21 glue into 321, then 40 and 6 into 406. In total 321 + 406 = 727.
cards=[12, 5, 9] → 134
12 and 9 give 129, and the lone card 5 is added as it is: 129 + 5 = 134.
cards=[8] → 8
cards=[3, 40, 6, 21]
727
Run checks the first 3 tests in your browser. Submit checks all 116 tests on the server, hidden ones included.