#x86-16 Assembly, 56 4141 39 bytes
00000000: b103 33ed ac8b fe51 f2ae 7503 45eb f995f983 ..3....Q..u.E...
00000010: 3c03fd03 7504 80c2 4d43 03d803dd 59e2 e592 85db7502 <..u...MC..Y....u.
00000020: 7502 040a 3c64 7201 43 u. ..<dr.C
B1 03 MOV CL, 3 ; set up loop counter for 3 digits
DIGIT_LOOP:
33 ED XOR BP, BP ; clear digit match counter
AC LODSB ; next digit char into AL
8B FE MOV DI, SI ; start search at next char
51 PUSH CX ; save outer digit loop counter
MATCH_LOOP:
F2/ AE REPNZ SCASB ; search until digit in AL is found
75 03 JNZ CHECK_FOUR ; is end of search string found?
45 INC BP ; otherwiseif not, a match was found, increment count
EB F9 JMP MATCH_LOOP ; continue looping
CHECK_FOUR:
95 XCHG BP, AX ; match counter results to AX for shorter compare83
3CFD 03 CMP ALBP, 3 ; is four of a kind?
75 04 JNE SCORE_DIGIT ; if not, add number of matches to 1UP's
80 C2 4D ADD DL, 77 ; add 77 to coin count
43 INC BX ; +1 1UP extra for four-of-a-kind
SCORE_DIGIT:
03 D8DD ADD BX, AXBP ; Add number of matches to total, set ZF if 0
59 POP CX ; restore outer digit loop position
E2 E5 LOOP DIGIT_LOOP ; keep looping
92 XCHG DX, AX ; coin count to AX for shorter compare
85 DB TEST BX, BX ; was ending score 0?
75 02 JNZ FINAL_SCORE ; if not,1UPs goare to0, calculate score
04 0A ADD AL, 10 ; consolation prize of 10
FINAL_SCORE:
3C 64 CMP AL, 100 ; is coin score over 100?
72 01 JB DONE ; if not, no extra 1UP
43 INC BX ; otherwise, increment 1UP
DONE:
Input starting coin count in DX
, SI
pointing to arraystart of "icons""icon" bytes (which can be '1'
-'5'
, or any byte value). Output the number of 1UP's in BX
.
The input of four bytes areis iterated and for each digit,compared to the remaining digitsbytes to the right are compared, andcounting the number of matches counted. TheThe scores for each type of match are awarded and add up to the total according to. Since a four-of-a-kind is also three-of-a-kind and also a one-pair, the followingvalue of each score type can be decomposed as follows:
2 [2, 2, 2] = 3 matches (= 4 1UP's + 77 coins)
2 [2, 2] = 2 matches (= 2 1UP's)
2 [2] = 1 match (= 1 1UP)
2 [5, 2, 2] = 2 matches (= 2 1UP's)
5 [2, 2] = 0 matches
2 [2] = 1 match (= 1 1UP)
4 [5, 5, 4] = 1 match (= 1 1UP)
5 [5, 4] = 1 match (= 1 1UP)
5 [4] = 0 matches
2 [3, 4, 3] = 0 matches
3 [4, 3] = 1 match (= 1 1UP)
4 [3] = 0 matches
If number of earned 1UP's is 0 at the end, 10 coins are awarded. If total coins are overgreater than 100, an additional 1UP is addedawarded.