#x86-16 Assembly, IBM PC DOS, 56 bytes **Binary:** 00000000: 50b1 0333 d2ac 8bfe 51f2 ae75 0342 ebf9 P..3....Q..u.B.. 00000010: 923c 0375 0481 c3dd 013c 0275 0481 c3c8 .<.u.....<.u.... 00000020: 003c 0175 0383 c364 59e2 d885 db75 02b3 .<.u...dY....u.. 00000030: 0a58 03c3 b264 f6f2 .X...d.. **Unassembled:** 50 PUSH AX ; save original coin count B1 03 MOV CL, 3 ; set up loop counter for 3 remaining digits DIGIT_LOOP: 33 D2 XOR DX, DX ; clear match counter AC LODSB ; next digit char into AL 8B FE MOV DI, SI ; start searching at next char 51 PUSH CX ; save outer loop counter MATCH_LOOP: F2/ AE REPNZ SCASB ; search until digit AL is found 75 03 JNZ CHECK_RES ; end of search string found 42 INC DX ; otherwise a match was found, inc counter EB F9 JMP MATCH_LOOP ; continue looping CHECK_RES: 92 XCHG DX, AX ; save match results to AX for shorter compare 3C 03 CMP AL, 3 ; is four of a kind? 75 04 JNE CHECK_THREE ; if not, check for triple 81 C3 01DD ADD BX, 477 ; if so, add 477 to score CHECK_THREE: 3C 02 CMP AL, 2 ; is three of a kind? 75 04 JNE CHECK_TWO ; if not, check for double 81 C3 00C8 ADD BX, 200 ; if so, add 200 to score CHECK_TWO: 3C 01 CMP AL, 1 ; is two of a kind? 75 03 JNE END_LOOP ; if not, move on to next 83 C3 64 ADD BX, 100 ; if so, add 100 to score END_LOOP: 59 POP CX ; restore outer loop position E2 D8 LOOP DIGIT_LOOP ; keep looping 85 DB TEST BX, BX ; was ending score 0? 75 03 JNZ DONE ; if not, go to calculate score B3 0A MOV BL, 10 ; consolation prize of 10 DONE: 58 POP AX ; restore original coins 03 C3 ADD AX, BX ; add earned score B2 64 MOV DL, 100 ; divide by 100 F6 F2 DIV DL ; result is in AL Input original coin count in `AX`, `SI` pointing to array of "icons" (which can be `'1'`-`'5'`, or any byte value). Output number of lives in `AL`. **Explanation:** The input of four bytes are iterated and for each digit, the remaining digits to the right are compared and the number of matches counted. The "components" for that match are awarded and add up to the total. Think of four-of-a-kind as one-pair (100 coins), plus a three-of-a-kind "bonus" (200 coins), plus a four-of-a-kind "bonus" (477 coins) totaling 777 coins. Other hands work the same. Example: `[2, 2, 2, 2]` (four-of-a-kind) - 777 coins 2 [2, 2, 2] == 3 matches (477 coins -> Four-of-a-kind "bonus") 2 [2, 2] == 2 matches (200 coins -> Three-of-a-kind "bonus") 2 [2] == 1 match (100 coins -> One Pair) Example: `[2, 5, 2, 2]` (three-of-a-kind) - 300 coins 2 [5, 2, 2] == 2 matches (200 coins -> Three-of-a-kind "bonus") 5 [2, 2] == 0 matches 2 [2] == 1 match (100 coins -> One Pair) Example: `[4, 5, 5, 4]` (two pair) - 200 coins 4 [5, 5, 4] == 1 match (100 coins -> One Pair) 5 [5, 4] == 1 match (100 coins -> One Pair) 5 [4] == 0 matches Example: `[2, 3, 4, 3]` (one pair) - 100 coins 2 [3, 4, 3] == 0 matches 3 [4, 3] == 1 match (100 coins -> One Pair) 4 [3] == 0 matches If score is 0 at the end, 10 coins are awarded. This may not be the shortest possible way to do this, but it codes neatly enough into ASM. Here is a test program for PC DOS that includes extra routines to handle the integer value I/O: [![enter image description here][1]][1] Download and test [LUCKY.COM][2] for DOS. [1]: https://i.sstatic.net/0XZfJ.png [2]: https://stage.stonedrop.com/ppcg/LUCKY.COM