Skip to main content
Commonmark migration
Source Link

#x86-16 Assembly, 56 41 39 bytes

x86-16 Assembly, 56 41 39 bytes

#x86-16 Assembly, 56 41 39 bytes

x86-16 Assembly, 56 41 39 bytes

more readable examples
Source Link
640KB
  • 11.9k
  • 2
  • 35
  • 57
B1 03           MOV  CL, 3              ; set up loop counter for 3 digits
            DIGIT_LOOP: 
33 ED           XOR  BP, BP             ; clear digit matchmatches counter in BP
AC              LODSB                   ; load next digit char into AL
8B FE           MOV  DI, SI             ; start searchsearching 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?
45              INC  BP                 ; if not, a match was found, increment count
EB F9           JMP  MATCH_LOOP         ; continue looping 
            CHECK_FOUR: 
83 FD 03        CMP  BP, 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 DD           ADD  BX, BP             ; 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
75 02           JNZ  FINAL_SCORE        ; if 1UPs are> 0, calculateno scoreconsolation prize
04 0A           ADD  AL, 10             ; consolation prize ofaward 10 coins
            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:

Example: Examples:

[2, 2, 2, 2] (four-of-a-kind) = 7 1UP's + 77 coins

Example: [2, 5, 2, 2] (three-of-a-kind) = 3 1UP's

Example: [4, 5, 5, 4] (two pair) = 2 1UP's

Example: [2, 3, 4, 3] (one pair) = 1 1UP

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?
45              INC  BP                 ; if not, a match was found, increment count
EB F9           JMP  MATCH_LOOP         ; continue looping 
            CHECK_FOUR: 
83 FD 03        CMP  BP, 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 DD           ADD  BX, BP             ; 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
75 02           JNZ  FINAL_SCORE        ; if 1UPs are 0, 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:

Example: [2, 2, 2, 2] (four-of-a-kind) = 7 1UP's + 77 coins

Example: [2, 5, 2, 2] (three-of-a-kind) = 3 1UP's

Example: [4, 5, 5, 4] (two pair) = 2 1UP's

Example: [2, 3, 4, 3] (one pair) = 1 1UP

B1 03           MOV  CL, 3              ; set up loop counter for 3 digits
            DIGIT_LOOP: 
33 ED           XOR  BP, BP             ; clear digit matches counter in BP
AC              LODSB                   ; load next digit char into AL
8B FE           MOV  DI, SI             ; start searching 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?
45              INC  BP                 ; if not, a match was found, increment count
EB F9           JMP  MATCH_LOOP         ; continue looping 
            CHECK_FOUR: 
83 FD 03        CMP  BP, 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 DD           ADD  BX, BP             ; 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
75 02           JNZ  FINAL_SCORE        ; if 1UPs > 0, no consolation prize
04 0A           ADD  AL, 10             ; award 10 coins
            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:

Examples:

[2, 2, 2, 2] (four-of-a-kind) = 7 1UP's + 77 coins

[2, 5, 2, 2] (three-of-a-kind) = 3 1UP's

[4, 5, 5, 4] (two pair) = 2 1UP's

[2, 3, 4, 3] (one pair) = 1 1UP

-2 bytes, remove redundant test for 0, more proofreading
Source Link
640KB
  • 11.9k
  • 2
  • 35
  • 57

#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.

#x86-16 Assembly, 56 41 bytes

00000000: b103 33ed ac8b fe51 f2ae 7503 45eb f995  ..3....Q..u.E...
00000010: 3c03 7504 80c2 4d43 03d8 59e2 e592 85db  <.u...MC..Y.....
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 AL is found 
75 03           JNZ  CHECK_FOUR         ; end of search string found
45              INC  BP                 ; otherwise 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 compare 
3C 03           CMP  AL, 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 D8           ADD  BX, AX             ; Add number of matches to total
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, go to 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 array of "icons" (which can be '1'-'5', or any byte value). Output number of 1UP's in BX.

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 scores for each type of match are awarded and add up to the total according to the following:

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 over 100, an additional 1UP is added.

#x86-16 Assembly, 56 41 39 bytes

00000000: b103 33ed ac8b fe51 f2ae 7503 45eb f983  ..3....Q..u.E...
00000010: fd03 7504 80c2 4d43 03dd 59e2 e592 7502  ..u...MC..Y...u.
00000020: 040a 3c64 7201 43                        ..<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?
45              INC  BP                 ; if not, a match was found, increment count
EB F9           JMP  MATCH_LOOP         ; continue looping 
            CHECK_FOUR: 
83 FD 03        CMP  BP, 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 DD           ADD  BX, BP             ; 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
75 02           JNZ  FINAL_SCORE        ; if 1UPs are 0, 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 start of "icon" bytes (which can be '1'-'5', or any byte value). Output the number of 1UP's in BX.

The input of four bytes is iterated and compared to the remaining bytes to the right, counting the number of matches. The scores for each type of match are awarded and add up to the total. Since a four-of-a-kind is also three-of-a-kind and also a one-pair, the value 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 greater than 100, an additional 1UP is awarded.

deleted 45 characters in body; deleted 12 characters in body
Source Link
640KB
  • 11.9k
  • 2
  • 35
  • 57
Loading
comment fixes
Source Link
640KB
  • 11.9k
  • 2
  • 35
  • 57
Loading
-15 bytes, there's no need to calculate the actual score
Source Link
640KB
  • 11.9k
  • 2
  • 35
  • 57
Loading
add explanation
Source Link
640KB
  • 11.9k
  • 2
  • 35
  • 57
Loading
Source Link
640KB
  • 11.9k
  • 2
  • 35
  • 57
Loading