Nothing like a good ol' game of ModTenTips for golfing in 05AB1EScore a Cribbage HandCompare two poker...
How do I get toddlers to stop asking for food every hour?
How do proponents of Sola Scriptura address the ministry of those Apostles who authored no parts of Scripture?
Are modern clipless shoes and pedals that much better than toe clips and straps?
Does Norwegian overbook flights?
Handling Disruptive Student on the Autistic Spectrum
Compelling story with the world as a villain
Architectural feasibility of a tiered circular stone keep
Duplicate instruments in unison in an orchestra
Does an atom recoil when photon radiate?
Is gzip atomic?
How long do you think advanced cybernetic implants would plausibly last?
Numbers Decrease while Letters Increase
Two questions about typesetting a Roman missal
Is "The life is beautiful" incorrect or just very non-idiomatic?
Sum ergo cogito?
Nothing like a good ol' game of ModTen
Was it ever possible to target a zone?
Are the A380 engines interchangeable (given they are not all equipped with reverse)?
Did the Cheela on Dragon's Egg have twelve-stranded "DNA"?
Network helper class with retry logic on failure
How do I, an introvert, communicate to my friend and only colleague, an extrovert, that I want to spend my scheduled breaks without them?
Circular Reasoning for Epsilon-Delta Proof?
Duplicate Files
Why is 1. d4 Nf6 2. c4 e6 3. Bg5 almost never played?
Nothing like a good ol' game of ModTen
Tips for golfing in 05AB1EScore a Cribbage HandCompare two poker handsWho wins a Spades trickDetermine the winner of a game of WarScore a hand of HeartsChoose the last card in a poker hand1326 starting hold'em combosBadugi, Who Wins?Professor at MIT can read minds!
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}
$begingroup$
Disclaimer: ModTen is a fictional card game which was created for the sole purpose of this challenge.
The rules of ModTen
ModTen is played with a standard 52-card deck. Because the full rules are yet to be invented, we're going to focus on the hand ranking exclusively.
A winning hand in ModTen. Graphics from Wikipedia.
Card values
The cards have the following values:
2 to 9: worth their face value
Ten: 0 point
Jack: 3 points
Queen or King: 8 points
Ace: 9 points
Hand values
A ModTen hand is made of two cards. The base value of a hand is obtained by multiplying the value of both cards together and keeping the last digit only (i.e. applying a modulo 10).
For instance, the value of 7♥ - Q♣ is "$6$", because $(7times8)bmod 10=6$.
The only other rule in ModTen is that suited cards are worth more than unsuited ones. By convention, we are going to append a "s" to the value if both cards are of the same suit.
For instance, the value of 9♠ - 5♠ will be noted as "$5text{s}$", because $(9times5)bmod 10=5$ and the cards are suited.
Hand ranking and winner
The above rules result in 18 distinct hand ranks which are summarized in the following table, from strongest to lowest (or rarest to most common). The probabilities are given for information only.
Given two hands, the hand with the lowest rank wins. If both hands are of the same rank, then it's a draw (there's no tie breaker).
hand rank | hand value(s) | deal probability
-----------+---------------+------------------
1 | 9s | 0.30%
2 | 3s | 0.60%
3 | 1s | 0.90%
4 | 7s | 1.21%
5 | 5s | 1.51%
6 | 3 | 1.81%
7 | 9 | 2.26%
8 | 8s | 2.71%
9 | 6s | 3.02%
10 | 1 or 7 | 3.62% each
11 | 2s or 4s | 3.92% each
12 | 5 | 4.98%
13 | 0s | 5.43%
14 | 8 | 8.14%
15 | 6 | 9.95%
16 | 2 | 11.76%
17 | 4 | 13.57%
18 | 0 | 16.74%
The challenge
Given two ModTen hands, output one of three consistent values of your choice to tell whether:
- the first player wins
- the second player wins
- it's a draw
The following rules apply:
- A card must be described by its rank in upper case (
2
,3
, ...,9
,T
,J
,Q
,K
orA
) followed by its suit in lower case (c
,d
,h
ors
, for clubs, diamonds, hearts and spades). - You may use
"10"
instead of"T"
but any other substitution is prohibited.
As long as the above rules are followed, you may take the hands in any reasonable and unambiguous format. You are allowed to take the rank and the suit as two distinct characters rather than a single string.
Some valid input formats are:
"7c Qh 8s Ks"
[["7c","Qh"], ["8s","Ks"]]
[[['7','c'], ['Q','h']], [['8','s'], ['K','s']]]
- etc.
Instead of using 3 consistent distinct values, your output may also be negative, positive or zero. Please specify the output format used in your answer.
- This is code-golf.
Test cases
Player 1 wins
["Js","3s"], ["Ks","Kh"]
["7h","9h"], ["9s","7c"]
["Ah","5s"], ["Ts","8s"]
["Ts","8s"], ["Jh","2s"]
["4h","8s"], ["Qh","Ks"]
Player 2 wins
["Th","8d"], ["6s","Kd"]
["Jc","5c"], ["3s","9s"]
["Jc","Jd"], ["9h","Ah"]
["2d","4d"], ["3h","3s"]
["5c","4c"], ["3c","2c"]
Draw
["Js","3s"], ["3d","Jd"]
["Ah","Ac"], ["3d","9s"]
["Qc","Kc"], ["6d","4d"]
["2d","3d"], ["3s","2s"]
["Ts","9c"], ["4h","5d"]
code-golf card-games
$endgroup$
add a comment |
$begingroup$
Disclaimer: ModTen is a fictional card game which was created for the sole purpose of this challenge.
The rules of ModTen
ModTen is played with a standard 52-card deck. Because the full rules are yet to be invented, we're going to focus on the hand ranking exclusively.
A winning hand in ModTen. Graphics from Wikipedia.
Card values
The cards have the following values:
2 to 9: worth their face value
Ten: 0 point
Jack: 3 points
Queen or King: 8 points
Ace: 9 points
Hand values
A ModTen hand is made of two cards. The base value of a hand is obtained by multiplying the value of both cards together and keeping the last digit only (i.e. applying a modulo 10).
For instance, the value of 7♥ - Q♣ is "$6$", because $(7times8)bmod 10=6$.
The only other rule in ModTen is that suited cards are worth more than unsuited ones. By convention, we are going to append a "s" to the value if both cards are of the same suit.
For instance, the value of 9♠ - 5♠ will be noted as "$5text{s}$", because $(9times5)bmod 10=5$ and the cards are suited.
Hand ranking and winner
The above rules result in 18 distinct hand ranks which are summarized in the following table, from strongest to lowest (or rarest to most common). The probabilities are given for information only.
Given two hands, the hand with the lowest rank wins. If both hands are of the same rank, then it's a draw (there's no tie breaker).
hand rank | hand value(s) | deal probability
-----------+---------------+------------------
1 | 9s | 0.30%
2 | 3s | 0.60%
3 | 1s | 0.90%
4 | 7s | 1.21%
5 | 5s | 1.51%
6 | 3 | 1.81%
7 | 9 | 2.26%
8 | 8s | 2.71%
9 | 6s | 3.02%
10 | 1 or 7 | 3.62% each
11 | 2s or 4s | 3.92% each
12 | 5 | 4.98%
13 | 0s | 5.43%
14 | 8 | 8.14%
15 | 6 | 9.95%
16 | 2 | 11.76%
17 | 4 | 13.57%
18 | 0 | 16.74%
The challenge
Given two ModTen hands, output one of three consistent values of your choice to tell whether:
- the first player wins
- the second player wins
- it's a draw
The following rules apply:
- A card must be described by its rank in upper case (
2
,3
, ...,9
,T
,J
,Q
,K
orA
) followed by its suit in lower case (c
,d
,h
ors
, for clubs, diamonds, hearts and spades). - You may use
"10"
instead of"T"
but any other substitution is prohibited.
As long as the above rules are followed, you may take the hands in any reasonable and unambiguous format. You are allowed to take the rank and the suit as two distinct characters rather than a single string.
Some valid input formats are:
"7c Qh 8s Ks"
[["7c","Qh"], ["8s","Ks"]]
[[['7','c'], ['Q','h']], [['8','s'], ['K','s']]]
- etc.
Instead of using 3 consistent distinct values, your output may also be negative, positive or zero. Please specify the output format used in your answer.
- This is code-golf.
Test cases
Player 1 wins
["Js","3s"], ["Ks","Kh"]
["7h","9h"], ["9s","7c"]
["Ah","5s"], ["Ts","8s"]
["Ts","8s"], ["Jh","2s"]
["4h","8s"], ["Qh","Ks"]
Player 2 wins
["Th","8d"], ["6s","Kd"]
["Jc","5c"], ["3s","9s"]
["Jc","Jd"], ["9h","Ah"]
["2d","4d"], ["3h","3s"]
["5c","4c"], ["3c","2c"]
Draw
["Js","3s"], ["3d","Jd"]
["Ah","Ac"], ["3d","9s"]
["Qc","Kc"], ["6d","4d"]
["2d","3d"], ["3s","2s"]
["Ts","9c"], ["4h","5d"]
code-golf card-games
$endgroup$
$begingroup$
What about taking enums as input? Haskell has a pretty powerful type system; I'm fairly sure something like this could be made directly in it.
$endgroup$
– wizzwizz4
yesterday
$begingroup$
This isn't Haskell, but would{{J, s}, {3, s}}
be okay?
$endgroup$
– wizzwizz4
yesterday
1
$begingroup$
@wizzwizz4 Yes, that's fine.
$endgroup$
– Arnauld
yesterday
$begingroup$
This might be clearer with "hands of cards with matching suits" instead of "suited cards".
$endgroup$
– chrylis
10 hours ago
add a comment |
$begingroup$
Disclaimer: ModTen is a fictional card game which was created for the sole purpose of this challenge.
The rules of ModTen
ModTen is played with a standard 52-card deck. Because the full rules are yet to be invented, we're going to focus on the hand ranking exclusively.
A winning hand in ModTen. Graphics from Wikipedia.
Card values
The cards have the following values:
2 to 9: worth their face value
Ten: 0 point
Jack: 3 points
Queen or King: 8 points
Ace: 9 points
Hand values
A ModTen hand is made of two cards. The base value of a hand is obtained by multiplying the value of both cards together and keeping the last digit only (i.e. applying a modulo 10).
For instance, the value of 7♥ - Q♣ is "$6$", because $(7times8)bmod 10=6$.
The only other rule in ModTen is that suited cards are worth more than unsuited ones. By convention, we are going to append a "s" to the value if both cards are of the same suit.
For instance, the value of 9♠ - 5♠ will be noted as "$5text{s}$", because $(9times5)bmod 10=5$ and the cards are suited.
Hand ranking and winner
The above rules result in 18 distinct hand ranks which are summarized in the following table, from strongest to lowest (or rarest to most common). The probabilities are given for information only.
Given two hands, the hand with the lowest rank wins. If both hands are of the same rank, then it's a draw (there's no tie breaker).
hand rank | hand value(s) | deal probability
-----------+---------------+------------------
1 | 9s | 0.30%
2 | 3s | 0.60%
3 | 1s | 0.90%
4 | 7s | 1.21%
5 | 5s | 1.51%
6 | 3 | 1.81%
7 | 9 | 2.26%
8 | 8s | 2.71%
9 | 6s | 3.02%
10 | 1 or 7 | 3.62% each
11 | 2s or 4s | 3.92% each
12 | 5 | 4.98%
13 | 0s | 5.43%
14 | 8 | 8.14%
15 | 6 | 9.95%
16 | 2 | 11.76%
17 | 4 | 13.57%
18 | 0 | 16.74%
The challenge
Given two ModTen hands, output one of three consistent values of your choice to tell whether:
- the first player wins
- the second player wins
- it's a draw
The following rules apply:
- A card must be described by its rank in upper case (
2
,3
, ...,9
,T
,J
,Q
,K
orA
) followed by its suit in lower case (c
,d
,h
ors
, for clubs, diamonds, hearts and spades). - You may use
"10"
instead of"T"
but any other substitution is prohibited.
As long as the above rules are followed, you may take the hands in any reasonable and unambiguous format. You are allowed to take the rank and the suit as two distinct characters rather than a single string.
Some valid input formats are:
"7c Qh 8s Ks"
[["7c","Qh"], ["8s","Ks"]]
[[['7','c'], ['Q','h']], [['8','s'], ['K','s']]]
- etc.
Instead of using 3 consistent distinct values, your output may also be negative, positive or zero. Please specify the output format used in your answer.
- This is code-golf.
Test cases
Player 1 wins
["Js","3s"], ["Ks","Kh"]
["7h","9h"], ["9s","7c"]
["Ah","5s"], ["Ts","8s"]
["Ts","8s"], ["Jh","2s"]
["4h","8s"], ["Qh","Ks"]
Player 2 wins
["Th","8d"], ["6s","Kd"]
["Jc","5c"], ["3s","9s"]
["Jc","Jd"], ["9h","Ah"]
["2d","4d"], ["3h","3s"]
["5c","4c"], ["3c","2c"]
Draw
["Js","3s"], ["3d","Jd"]
["Ah","Ac"], ["3d","9s"]
["Qc","Kc"], ["6d","4d"]
["2d","3d"], ["3s","2s"]
["Ts","9c"], ["4h","5d"]
code-golf card-games
$endgroup$
Disclaimer: ModTen is a fictional card game which was created for the sole purpose of this challenge.
The rules of ModTen
ModTen is played with a standard 52-card deck. Because the full rules are yet to be invented, we're going to focus on the hand ranking exclusively.
A winning hand in ModTen. Graphics from Wikipedia.
Card values
The cards have the following values:
2 to 9: worth their face value
Ten: 0 point
Jack: 3 points
Queen or King: 8 points
Ace: 9 points
Hand values
A ModTen hand is made of two cards. The base value of a hand is obtained by multiplying the value of both cards together and keeping the last digit only (i.e. applying a modulo 10).
For instance, the value of 7♥ - Q♣ is "$6$", because $(7times8)bmod 10=6$.
The only other rule in ModTen is that suited cards are worth more than unsuited ones. By convention, we are going to append a "s" to the value if both cards are of the same suit.
For instance, the value of 9♠ - 5♠ will be noted as "$5text{s}$", because $(9times5)bmod 10=5$ and the cards are suited.
Hand ranking and winner
The above rules result in 18 distinct hand ranks which are summarized in the following table, from strongest to lowest (or rarest to most common). The probabilities are given for information only.
Given two hands, the hand with the lowest rank wins. If both hands are of the same rank, then it's a draw (there's no tie breaker).
hand rank | hand value(s) | deal probability
-----------+---------------+------------------
1 | 9s | 0.30%
2 | 3s | 0.60%
3 | 1s | 0.90%
4 | 7s | 1.21%
5 | 5s | 1.51%
6 | 3 | 1.81%
7 | 9 | 2.26%
8 | 8s | 2.71%
9 | 6s | 3.02%
10 | 1 or 7 | 3.62% each
11 | 2s or 4s | 3.92% each
12 | 5 | 4.98%
13 | 0s | 5.43%
14 | 8 | 8.14%
15 | 6 | 9.95%
16 | 2 | 11.76%
17 | 4 | 13.57%
18 | 0 | 16.74%
The challenge
Given two ModTen hands, output one of three consistent values of your choice to tell whether:
- the first player wins
- the second player wins
- it's a draw
The following rules apply:
- A card must be described by its rank in upper case (
2
,3
, ...,9
,T
,J
,Q
,K
orA
) followed by its suit in lower case (c
,d
,h
ors
, for clubs, diamonds, hearts and spades). - You may use
"10"
instead of"T"
but any other substitution is prohibited.
As long as the above rules are followed, you may take the hands in any reasonable and unambiguous format. You are allowed to take the rank and the suit as two distinct characters rather than a single string.
Some valid input formats are:
"7c Qh 8s Ks"
[["7c","Qh"], ["8s","Ks"]]
[[['7','c'], ['Q','h']], [['8','s'], ['K','s']]]
- etc.
Instead of using 3 consistent distinct values, your output may also be negative, positive or zero. Please specify the output format used in your answer.
- This is code-golf.
Test cases
Player 1 wins
["Js","3s"], ["Ks","Kh"]
["7h","9h"], ["9s","7c"]
["Ah","5s"], ["Ts","8s"]
["Ts","8s"], ["Jh","2s"]
["4h","8s"], ["Qh","Ks"]
Player 2 wins
["Th","8d"], ["6s","Kd"]
["Jc","5c"], ["3s","9s"]
["Jc","Jd"], ["9h","Ah"]
["2d","4d"], ["3h","3s"]
["5c","4c"], ["3c","2c"]
Draw
["Js","3s"], ["3d","Jd"]
["Ah","Ac"], ["3d","9s"]
["Qc","Kc"], ["6d","4d"]
["2d","3d"], ["3s","2s"]
["Ts","9c"], ["4h","5d"]
code-golf card-games
code-golf card-games
edited yesterday
Arnauld
asked yesterday
ArnauldArnauld
91k7 gold badges106 silver badges371 bronze badges
91k7 gold badges106 silver badges371 bronze badges
$begingroup$
What about taking enums as input? Haskell has a pretty powerful type system; I'm fairly sure something like this could be made directly in it.
$endgroup$
– wizzwizz4
yesterday
$begingroup$
This isn't Haskell, but would{{J, s}, {3, s}}
be okay?
$endgroup$
– wizzwizz4
yesterday
1
$begingroup$
@wizzwizz4 Yes, that's fine.
$endgroup$
– Arnauld
yesterday
$begingroup$
This might be clearer with "hands of cards with matching suits" instead of "suited cards".
$endgroup$
– chrylis
10 hours ago
add a comment |
$begingroup$
What about taking enums as input? Haskell has a pretty powerful type system; I'm fairly sure something like this could be made directly in it.
$endgroup$
– wizzwizz4
yesterday
$begingroup$
This isn't Haskell, but would{{J, s}, {3, s}}
be okay?
$endgroup$
– wizzwizz4
yesterday
1
$begingroup$
@wizzwizz4 Yes, that's fine.
$endgroup$
– Arnauld
yesterday
$begingroup$
This might be clearer with "hands of cards with matching suits" instead of "suited cards".
$endgroup$
– chrylis
10 hours ago
$begingroup$
What about taking enums as input? Haskell has a pretty powerful type system; I'm fairly sure something like this could be made directly in it.
$endgroup$
– wizzwizz4
yesterday
$begingroup$
What about taking enums as input? Haskell has a pretty powerful type system; I'm fairly sure something like this could be made directly in it.
$endgroup$
– wizzwizz4
yesterday
$begingroup$
This isn't Haskell, but would
{{J, s}, {3, s}}
be okay?$endgroup$
– wizzwizz4
yesterday
$begingroup$
This isn't Haskell, but would
{{J, s}, {3, s}}
be okay?$endgroup$
– wizzwizz4
yesterday
1
1
$begingroup$
@wizzwizz4 Yes, that's fine.
$endgroup$
– Arnauld
yesterday
$begingroup$
@wizzwizz4 Yes, that's fine.
$endgroup$
– Arnauld
yesterday
$begingroup$
This might be clearer with "hands of cards with matching suits" instead of "suited cards".
$endgroup$
– chrylis
10 hours ago
$begingroup$
This might be clearer with "hands of cards with matching suits" instead of "suited cards".
$endgroup$
– chrylis
10 hours ago
add a comment |
10 Answers
10
active
oldest
votes
$begingroup$
Python 3, 165 142 130 129 bytes
lambda m,n:p(*n)-p(*m)
v="T 23456789 J QA K".find
p=lambda i,s,j,t:ord("HC92FA51GAB4E893D760"[s==t::2][v(j)*v(i)%10])
Try it online!
-23 bytes thanks to @Jonathan Allan
-2 bytes thanks to @ovs
-1 byte thanks to @mypetlion
Ungolfed:
f = lambda hand1, hand2: get_rank(*hand2) - get_rank(*hand1)
def get_rank(v1, suit1, v2, suit2):
get_card_value = "T 23456789 J QA K".find
# rank_table = [[17,9,15,5,16,11,14,9,13,6],[12,2,10,1,10,4,8,3,7,0]]
# rank_table = ("H9F5GBE9D6","C2A1A48370") # Base-18 encoding of ranks
rank_table = "HC92FA51GAB4E893D760" # Interleaved base-18 encoding
# ASCII-value decoding has the same ranking effect as base-18 decoding
return ord(rank_table[suit1 == suit2::2][get_card_value(v2) * get_card_value(v1) % 10])
The function f
takes two arguments representing the hand of player 1 and player 2. It returns a positive, negative, or zero value in the case of a player 1 win, a player 2 win, or a draw, correspondingly. Each hand is encoded as a single string, e.g. "7cQh".
New contributor
$endgroup$
3
$begingroup$
Hi Joel, welcome to CGCC! Very clever idea splitting the hand rank array in two! Keep 'em coming!
$endgroup$
– 640KB
yesterday
1
$begingroup$
@Jonathan Allan Thanks. I've incorporated your idea using slightly different approaches.
$endgroup$
– Joel
yesterday
1
$begingroup$
You can save 2 bytes by storing the rank table in a single string:"HC92FA51GAB4E893D760"[s==t::2]
$endgroup$
– ovs
yesterday
1
$begingroup$
And another 4 bytes shorter if you're willing to switch to Python 2. (cmp
is not available in Python 3)
$endgroup$
– ovs
yesterday
1
$begingroup$
You can usestr.find
instead ofstr.index
to save one byte. The only behaviour difference between the two methods is thatindex
throws an error when the element isn't found, whilefind
returns-1
. So it won't be an issue for your code.
$endgroup$
– mypetlion
yesterday
|
show 3 more comments
$begingroup$
x86-16 Assembly, 87 83 bytes
Binary:
00000000: e807 0050 e803 005a 3ac2 ad2c 3092 ad2c ...P...Z:..,0..,
00000010: 30bb 3501 3af4 7503 bb3f 01e8 0a00 92e8 0.5.:.u..?......
00000020: 0600 f6e2 d40a d7c3 b106 bf49 01f2 aee3 ...........I....
00000030: 038a 4504 c312 0a10 0611 0c0f 0a0e 070d ..E.............
00000040: 030b 020b 0509 0408 0124 1a21 1b11 0003 .........$.!....
00000050: 0808 09 ...
Unassembled:
E8 010A CALL GET_HAND ; score first hand, ranked score into AL
50 PUSH AX ; save score
E8 010A CALL GET_HAND ; score second hand
5A POP DX ; restore first hand into DL
3A C2 CMP AL, DL ; compare scores - result in CF, OF and ZF
GET_HAND PROC ; 4 char string to ranked score ("9s7c" -> 6)
AD LODSW ; load first card string
2C 30 SUB AL, '0' ; ASCII convert
92 XCHG DX, AX ; store in DX
AD LODSW ; load second card string
2C 30 SUB AL, '0' ; ASCII convert
BB 0139 MOV BX, OFFSET R ; first, point to non-suited table
3A F4 CMP DH, AH ; is it suited?
75 03 JNZ NO_SUIT
BB 0143 MOV BX, OFFSET RS ; point to suited table
NO_SUIT:
E8 012C CALL GET_VALUE ; get face card value in AL
92 XCHG DX, AX ; swap first and second cards
E8 012C CALL GET_VALUE ; get face card value in AL
F6 E2 MUL DL ; multiply values of two cards
D4 A0 AAM ; AL = AL mod 10
D7 XLAT ; lookup value in rank score table
C3 RET
GET_HAND ENDP
GET_VALUE PROC ; get value of a card (2 -> 2, J -> 3, A -> 9)
B1 06 MOV CL, 6 ; loop counter for scan
BF 014D MOV DI, OFFSET V ; load lookup table
F2/ AE REPNZ SCASB ; scan until match is found
E3 03 JCXZ NOT_FOUND ; if not found, keep original numeric value
8A 45 04 MOV AL, BYTE PTR[DI+4] ; if found, get corresponding value
NOT_FOUND:
C3 RET ; return to program
GET_VALUE ENDP
R DB 18, 10, 16, 6, 17, 12, 15, 10, 14, 7 ; unsuited score table
RS DB 13, 3, 11, 2, 11, 5, 9, 4, 8, 1 ; suited score table
V DB 'J'-'0','Q'-'0','K'-'0','A'-'0','T'-'0' ; face card score table
DB 3, 8, 8, 9, 0
Input is as a string such as Js3sKsKh
, at pointer in SI
. Output is ZF = 0 and SF = OF
(test with JG
) if player 1 wins, SF ≠ OF
(test with JL
) if player 2 wins or ZF
(test with JE
) if a draw.
Output using DOS test program:
Download and test MODTEN.COM for DOS.
$endgroup$
add a comment |
$begingroup$
05AB1E, 41 bytes
•V›{₆Ÿ&∊WÍj¸•19вIεø`ËT*s"JTQKA"Ž_Y‡Pθ+}èÆ
Input as a list of list of list of characters, like the third example input format in the challenge description. I.e. P1 7c Qh
& P2 8s Ks
would be input as [[["7","c"],["Q","h"]],[["8","s"],["K","s"]]]
. (And uses T
for 10
.)
Outputs a negative integer if player 1 wins; a positive integer if player 2 wins; or 0 if it's a draw.
Try it online or verify all test cases.
Explanation:
•V›{₆Ÿ&∊WÍj¸• # Push compressed integer 36742512464916394906012008
19в # Convert it to base-19 as list:
# [18,10,16,6,17,12,15,10,14,7,13,3,11,2,11,5,9,4,8,1]
Iε # Push the input, and map each of its hands to:
ø # Zip/transpose the hand; swapping rows/columns
# i.e. [["8","s"],["K","s"]] → [[["8","K"],["s","s"]]
` # Push them separated to the stack
Ë # Check if the two suits in the top list are equal (1/0 for truthy/falsey)
T* # Multiply that by 10 (so we now have 10 if the suits are equal; 0 if not)
s # Swap to get the list with the two values
"JTQKA" # Push string "JTQKA"
Ž_Y # Push compressed integer 30889
‡ # Transliterate these characters to these digits
P # Now take the product of the two values in the list
θ # Only leave the last digit (basically modulo-10)
+ # And add it to the 0/10
# (now we have the hand values of both players,
# where instead of a trailing "s" we have a leading 1)
}è # After the map: index each value into the earlier created integer-list
# (now we have the hand rank of both players)
Æ # And then reduce the resulting integers by subtracting
# (after which the result is output implicitly)
See this 05AB1E tip of mine (sections How to compress large integers? and How to compress integer lists?) to understand why •V›{₆Ÿ&∊WÍj¸•
is 36742512464916394906012008
, •V›{₆Ÿ&∊WÍj¸•19в
is [18,10,16,6,17,12,15,10,14,7,13,3,11,2,11,5,9,4,8,1]
and Ž_Y
is 30889
.
PS: "JTQKA"
could alternatively be .•∞ú₄•u
, but unfortunately it's the same byte-count. Only lowercase (non-dictionary) strings can be compressed in 05AB1E.
$endgroup$
add a comment |
$begingroup$
PHP, 212 185 178 149 bytes
while($p=$argv[++$x])$$x=ord(rjpfqlojngmckbkeidha[(($v=[J=>3,Q=>8,K=>8,A=>9])[$p[0]]?:$p[0])*($v[$p[2]]?:$p[2])%10+($p[1]==$p[3])*10]);echo${1}-${2};
Try it online!
- -7 bytes thanks to @Night2!
- -29 bytes by ASCII encoding the table instead of array
Input is via command line. Output to STDOUT
is negative if player 1 wins, positive if player 2 wins, 0
if tie. Example:
$ php modten.php Js3s KsKh
-1
$endgroup$
1
$begingroup$
@Night2 I suppose if I was willing to give us the spaceship operator (I mean, how often do you get to use that?), I could -2 bytes and just return negative, positive or zero, instead of-1
,1
or0
.
$endgroup$
– 640KB
9 hours ago
$begingroup$
I was amazed (in a good way) to see the spaceship operator in previous answer.
$endgroup$
– Night2
9 hours ago
add a comment |
$begingroup$
C (gcc), 172 167 165 164 bytes
p(l,v)char*l,*v;{v="T 23456789 J QA K";return"A<92?:51@:;4>893=760"[(l[1]==l[3])+(index(v,l[2])-v)*(index(v,*l)-v)%10*2];}f(char*s){return p(s+5)-p(s);}
Try it online!
2 bytes shaved off thanks to @ceilingcat!
Basically a port of @Joel's Python3 solution, but without the base18 encoding. Expects the input as one string with a space separating the hands of the two players, and outputs an integer that is positive, negative or zero to indicate player 1 wins, player 2 wins or if it's a draw.
$endgroup$
add a comment |
$begingroup$
Perl 6, 101 100 94 88 bytes
-1 byte thanks to Jo King
{[-] .map:{'HC92FA51GAB4E893D76'.ords[[*](.[*;0]>>.&{TR/JQKA/3889/})%10*2+[eq] .[*;1]]}}
Try it online!
Takes input as f(((<J ♠>, <3 ♠>), (<10 ♠>, <K ♥>)))
using 10
for Ten. Returns a value < 0 if player 1 wins, > 0 if player 2 wins, 0 if it's a draw.
Explanation
{
[-] # subtract values
.map:{ # map both hands
'HC92FA51GAB4E893D76'.ords[ # lookup rank in code point array
[*]( # multiply
.[*;0] # card ranks
>>.&{TR/JQKA/3889/} # translate J,Q,K,A to 3,8,8,9
)
%10*2 # mod 10 times 2
+[eq] .[*;1] # plus 1 if suited
]
}
}
$endgroup$
add a comment |
$begingroup$
Jelly, 46 bytes
“T0J3Q8K8A9”yⱮZV€P$Eƭ€)%⁵UḌị“©N¿!Æßvṅ?żṀ’b18¤I
Try it online!
A full program taking as its argument for example ["7h","Ks"],["4s","Ts"]
and printing zero if both players draw, positive if player 1 wins and negative if player 2 wins.
$endgroup$
add a comment |
$begingroup$
Charcoal, 97 bytes
≔”)¶&sNψU↓”ζF¹³F¹³F⁻⁴⁼ικ⊞υ⁺÷λ³⊗﹪Π⁺§ζι§ζκχ≔”A↘τ[⁵PkxτG”ε≔⁰δF⟦θη⟧≦⁻№υ⁺⁼§ι¹§ι³⊗﹪Π⁺§ζ⌕ε§ι⁰§ζ⌕ε§ι²χδIδ
Try it online! Link is to verbose version of code. Takes input as two strings of 4 characters e.g. QcKc
6d4d
and outputs a signed integer. Explanation:
≔”)¶&sNψU↓”ζ
Compressed string 2345678903889
represents the card values.
F¹³F¹³
Loop over each possible pair of values.
F⁻⁴⁼ικ
Loop over each possible second card suit. Without loss of generality we can assume that the first card has suit 3, so the second card suit can range from 0 to 3 unless the values are the same in which case it can only range from 0 to 2.
⊞υ⁺÷λ³⊗﹪Π⁺§ζι§ζκχ
Compute the modified score of the hand, which is the value of the hand doubled, plus 1 if the suits are the same (i.e. the second card has suit 3).
≔”A↘τ[⁵PkxτG”ε
Compressed string 23456789TJQKA
represents the card characters. The input cards are looked up in this string and then the position is used to index into the first string to get the card's value.
≔⁰δ
Initialise the result to 0.
F⟦θη⟧
Loop over the two hands.
≦⁻№υ⁺⁼§ι¹§ι³⊗﹪Π⁺§ζ⌕ε§ι⁰§ζ⌕ε§ι²χδ
Calculate the modified score of the hand, and thus its frequency, and subtract the result from this.
Iδ
Output the frequency difference.
$endgroup$
add a comment |
$begingroup$
C# (Visual C# Interactive Compiler), 139 bytes
x=>x.Sum(n=>(i++%2*2-1)*(n[1]==n[3]?"":" ")[n.Aggregate(1,(a,b)=>a*(b>85?1:b>83?0:b>74?8:b>73?3:b>64?9:b-48))%10]);int i
Try it online!
$endgroup$
add a comment |
$begingroup$
Perl 5 -p
, 107 bytes
$a=A;y/ATJQK/90388/;${$a++}=substr"IAG6HCFAE7D3B2B59481",($1eq$3).$&*$2%10,1while/.(.) (.)(.)/g;$_=$A cmp$B
Try it online!
Input:
As 4d,Th 8c
(Actually, the comma can be any character.)
Output:
-1 Player one wins
0 Draw
1 Player two wins
$endgroup$
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "200"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f190732%2fnothing-like-a-good-ol-game-of-modten%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
10 Answers
10
active
oldest
votes
10 Answers
10
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
Python 3, 165 142 130 129 bytes
lambda m,n:p(*n)-p(*m)
v="T 23456789 J QA K".find
p=lambda i,s,j,t:ord("HC92FA51GAB4E893D760"[s==t::2][v(j)*v(i)%10])
Try it online!
-23 bytes thanks to @Jonathan Allan
-2 bytes thanks to @ovs
-1 byte thanks to @mypetlion
Ungolfed:
f = lambda hand1, hand2: get_rank(*hand2) - get_rank(*hand1)
def get_rank(v1, suit1, v2, suit2):
get_card_value = "T 23456789 J QA K".find
# rank_table = [[17,9,15,5,16,11,14,9,13,6],[12,2,10,1,10,4,8,3,7,0]]
# rank_table = ("H9F5GBE9D6","C2A1A48370") # Base-18 encoding of ranks
rank_table = "HC92FA51GAB4E893D760" # Interleaved base-18 encoding
# ASCII-value decoding has the same ranking effect as base-18 decoding
return ord(rank_table[suit1 == suit2::2][get_card_value(v2) * get_card_value(v1) % 10])
The function f
takes two arguments representing the hand of player 1 and player 2. It returns a positive, negative, or zero value in the case of a player 1 win, a player 2 win, or a draw, correspondingly. Each hand is encoded as a single string, e.g. "7cQh".
New contributor
$endgroup$
3
$begingroup$
Hi Joel, welcome to CGCC! Very clever idea splitting the hand rank array in two! Keep 'em coming!
$endgroup$
– 640KB
yesterday
1
$begingroup$
@Jonathan Allan Thanks. I've incorporated your idea using slightly different approaches.
$endgroup$
– Joel
yesterday
1
$begingroup$
You can save 2 bytes by storing the rank table in a single string:"HC92FA51GAB4E893D760"[s==t::2]
$endgroup$
– ovs
yesterday
1
$begingroup$
And another 4 bytes shorter if you're willing to switch to Python 2. (cmp
is not available in Python 3)
$endgroup$
– ovs
yesterday
1
$begingroup$
You can usestr.find
instead ofstr.index
to save one byte. The only behaviour difference between the two methods is thatindex
throws an error when the element isn't found, whilefind
returns-1
. So it won't be an issue for your code.
$endgroup$
– mypetlion
yesterday
|
show 3 more comments
$begingroup$
Python 3, 165 142 130 129 bytes
lambda m,n:p(*n)-p(*m)
v="T 23456789 J QA K".find
p=lambda i,s,j,t:ord("HC92FA51GAB4E893D760"[s==t::2][v(j)*v(i)%10])
Try it online!
-23 bytes thanks to @Jonathan Allan
-2 bytes thanks to @ovs
-1 byte thanks to @mypetlion
Ungolfed:
f = lambda hand1, hand2: get_rank(*hand2) - get_rank(*hand1)
def get_rank(v1, suit1, v2, suit2):
get_card_value = "T 23456789 J QA K".find
# rank_table = [[17,9,15,5,16,11,14,9,13,6],[12,2,10,1,10,4,8,3,7,0]]
# rank_table = ("H9F5GBE9D6","C2A1A48370") # Base-18 encoding of ranks
rank_table = "HC92FA51GAB4E893D760" # Interleaved base-18 encoding
# ASCII-value decoding has the same ranking effect as base-18 decoding
return ord(rank_table[suit1 == suit2::2][get_card_value(v2) * get_card_value(v1) % 10])
The function f
takes two arguments representing the hand of player 1 and player 2. It returns a positive, negative, or zero value in the case of a player 1 win, a player 2 win, or a draw, correspondingly. Each hand is encoded as a single string, e.g. "7cQh".
New contributor
$endgroup$
3
$begingroup$
Hi Joel, welcome to CGCC! Very clever idea splitting the hand rank array in two! Keep 'em coming!
$endgroup$
– 640KB
yesterday
1
$begingroup$
@Jonathan Allan Thanks. I've incorporated your idea using slightly different approaches.
$endgroup$
– Joel
yesterday
1
$begingroup$
You can save 2 bytes by storing the rank table in a single string:"HC92FA51GAB4E893D760"[s==t::2]
$endgroup$
– ovs
yesterday
1
$begingroup$
And another 4 bytes shorter if you're willing to switch to Python 2. (cmp
is not available in Python 3)
$endgroup$
– ovs
yesterday
1
$begingroup$
You can usestr.find
instead ofstr.index
to save one byte. The only behaviour difference between the two methods is thatindex
throws an error when the element isn't found, whilefind
returns-1
. So it won't be an issue for your code.
$endgroup$
– mypetlion
yesterday
|
show 3 more comments
$begingroup$
Python 3, 165 142 130 129 bytes
lambda m,n:p(*n)-p(*m)
v="T 23456789 J QA K".find
p=lambda i,s,j,t:ord("HC92FA51GAB4E893D760"[s==t::2][v(j)*v(i)%10])
Try it online!
-23 bytes thanks to @Jonathan Allan
-2 bytes thanks to @ovs
-1 byte thanks to @mypetlion
Ungolfed:
f = lambda hand1, hand2: get_rank(*hand2) - get_rank(*hand1)
def get_rank(v1, suit1, v2, suit2):
get_card_value = "T 23456789 J QA K".find
# rank_table = [[17,9,15,5,16,11,14,9,13,6],[12,2,10,1,10,4,8,3,7,0]]
# rank_table = ("H9F5GBE9D6","C2A1A48370") # Base-18 encoding of ranks
rank_table = "HC92FA51GAB4E893D760" # Interleaved base-18 encoding
# ASCII-value decoding has the same ranking effect as base-18 decoding
return ord(rank_table[suit1 == suit2::2][get_card_value(v2) * get_card_value(v1) % 10])
The function f
takes two arguments representing the hand of player 1 and player 2. It returns a positive, negative, or zero value in the case of a player 1 win, a player 2 win, or a draw, correspondingly. Each hand is encoded as a single string, e.g. "7cQh".
New contributor
$endgroup$
Python 3, 165 142 130 129 bytes
lambda m,n:p(*n)-p(*m)
v="T 23456789 J QA K".find
p=lambda i,s,j,t:ord("HC92FA51GAB4E893D760"[s==t::2][v(j)*v(i)%10])
Try it online!
-23 bytes thanks to @Jonathan Allan
-2 bytes thanks to @ovs
-1 byte thanks to @mypetlion
Ungolfed:
f = lambda hand1, hand2: get_rank(*hand2) - get_rank(*hand1)
def get_rank(v1, suit1, v2, suit2):
get_card_value = "T 23456789 J QA K".find
# rank_table = [[17,9,15,5,16,11,14,9,13,6],[12,2,10,1,10,4,8,3,7,0]]
# rank_table = ("H9F5GBE9D6","C2A1A48370") # Base-18 encoding of ranks
rank_table = "HC92FA51GAB4E893D760" # Interleaved base-18 encoding
# ASCII-value decoding has the same ranking effect as base-18 decoding
return ord(rank_table[suit1 == suit2::2][get_card_value(v2) * get_card_value(v1) % 10])
The function f
takes two arguments representing the hand of player 1 and player 2. It returns a positive, negative, or zero value in the case of a player 1 win, a player 2 win, or a draw, correspondingly. Each hand is encoded as a single string, e.g. "7cQh".
New contributor
edited 6 hours ago
New contributor
answered yesterday
JoelJoel
1414 bronze badges
1414 bronze badges
New contributor
New contributor
3
$begingroup$
Hi Joel, welcome to CGCC! Very clever idea splitting the hand rank array in two! Keep 'em coming!
$endgroup$
– 640KB
yesterday
1
$begingroup$
@Jonathan Allan Thanks. I've incorporated your idea using slightly different approaches.
$endgroup$
– Joel
yesterday
1
$begingroup$
You can save 2 bytes by storing the rank table in a single string:"HC92FA51GAB4E893D760"[s==t::2]
$endgroup$
– ovs
yesterday
1
$begingroup$
And another 4 bytes shorter if you're willing to switch to Python 2. (cmp
is not available in Python 3)
$endgroup$
– ovs
yesterday
1
$begingroup$
You can usestr.find
instead ofstr.index
to save one byte. The only behaviour difference between the two methods is thatindex
throws an error when the element isn't found, whilefind
returns-1
. So it won't be an issue for your code.
$endgroup$
– mypetlion
yesterday
|
show 3 more comments
3
$begingroup$
Hi Joel, welcome to CGCC! Very clever idea splitting the hand rank array in two! Keep 'em coming!
$endgroup$
– 640KB
yesterday
1
$begingroup$
@Jonathan Allan Thanks. I've incorporated your idea using slightly different approaches.
$endgroup$
– Joel
yesterday
1
$begingroup$
You can save 2 bytes by storing the rank table in a single string:"HC92FA51GAB4E893D760"[s==t::2]
$endgroup$
– ovs
yesterday
1
$begingroup$
And another 4 bytes shorter if you're willing to switch to Python 2. (cmp
is not available in Python 3)
$endgroup$
– ovs
yesterday
1
$begingroup$
You can usestr.find
instead ofstr.index
to save one byte. The only behaviour difference between the two methods is thatindex
throws an error when the element isn't found, whilefind
returns-1
. So it won't be an issue for your code.
$endgroup$
– mypetlion
yesterday
3
3
$begingroup$
Hi Joel, welcome to CGCC! Very clever idea splitting the hand rank array in two! Keep 'em coming!
$endgroup$
– 640KB
yesterday
$begingroup$
Hi Joel, welcome to CGCC! Very clever idea splitting the hand rank array in two! Keep 'em coming!
$endgroup$
– 640KB
yesterday
1
1
$begingroup$
@Jonathan Allan Thanks. I've incorporated your idea using slightly different approaches.
$endgroup$
– Joel
yesterday
$begingroup$
@Jonathan Allan Thanks. I've incorporated your idea using slightly different approaches.
$endgroup$
– Joel
yesterday
1
1
$begingroup$
You can save 2 bytes by storing the rank table in a single string:
"HC92FA51GAB4E893D760"[s==t::2]
$endgroup$
– ovs
yesterday
$begingroup$
You can save 2 bytes by storing the rank table in a single string:
"HC92FA51GAB4E893D760"[s==t::2]
$endgroup$
– ovs
yesterday
1
1
$begingroup$
And another 4 bytes shorter if you're willing to switch to Python 2. (
cmp
is not available in Python 3)$endgroup$
– ovs
yesterday
$begingroup$
And another 4 bytes shorter if you're willing to switch to Python 2. (
cmp
is not available in Python 3)$endgroup$
– ovs
yesterday
1
1
$begingroup$
You can use
str.find
instead of str.index
to save one byte. The only behaviour difference between the two methods is that index
throws an error when the element isn't found, while find
returns -1
. So it won't be an issue for your code.$endgroup$
– mypetlion
yesterday
$begingroup$
You can use
str.find
instead of str.index
to save one byte. The only behaviour difference between the two methods is that index
throws an error when the element isn't found, while find
returns -1
. So it won't be an issue for your code.$endgroup$
– mypetlion
yesterday
|
show 3 more comments
$begingroup$
x86-16 Assembly, 87 83 bytes
Binary:
00000000: e807 0050 e803 005a 3ac2 ad2c 3092 ad2c ...P...Z:..,0..,
00000010: 30bb 3501 3af4 7503 bb3f 01e8 0a00 92e8 0.5.:.u..?......
00000020: 0600 f6e2 d40a d7c3 b106 bf49 01f2 aee3 ...........I....
00000030: 038a 4504 c312 0a10 0611 0c0f 0a0e 070d ..E.............
00000040: 030b 020b 0509 0408 0124 1a21 1b11 0003 .........$.!....
00000050: 0808 09 ...
Unassembled:
E8 010A CALL GET_HAND ; score first hand, ranked score into AL
50 PUSH AX ; save score
E8 010A CALL GET_HAND ; score second hand
5A POP DX ; restore first hand into DL
3A C2 CMP AL, DL ; compare scores - result in CF, OF and ZF
GET_HAND PROC ; 4 char string to ranked score ("9s7c" -> 6)
AD LODSW ; load first card string
2C 30 SUB AL, '0' ; ASCII convert
92 XCHG DX, AX ; store in DX
AD LODSW ; load second card string
2C 30 SUB AL, '0' ; ASCII convert
BB 0139 MOV BX, OFFSET R ; first, point to non-suited table
3A F4 CMP DH, AH ; is it suited?
75 03 JNZ NO_SUIT
BB 0143 MOV BX, OFFSET RS ; point to suited table
NO_SUIT:
E8 012C CALL GET_VALUE ; get face card value in AL
92 XCHG DX, AX ; swap first and second cards
E8 012C CALL GET_VALUE ; get face card value in AL
F6 E2 MUL DL ; multiply values of two cards
D4 A0 AAM ; AL = AL mod 10
D7 XLAT ; lookup value in rank score table
C3 RET
GET_HAND ENDP
GET_VALUE PROC ; get value of a card (2 -> 2, J -> 3, A -> 9)
B1 06 MOV CL, 6 ; loop counter for scan
BF 014D MOV DI, OFFSET V ; load lookup table
F2/ AE REPNZ SCASB ; scan until match is found
E3 03 JCXZ NOT_FOUND ; if not found, keep original numeric value
8A 45 04 MOV AL, BYTE PTR[DI+4] ; if found, get corresponding value
NOT_FOUND:
C3 RET ; return to program
GET_VALUE ENDP
R DB 18, 10, 16, 6, 17, 12, 15, 10, 14, 7 ; unsuited score table
RS DB 13, 3, 11, 2, 11, 5, 9, 4, 8, 1 ; suited score table
V DB 'J'-'0','Q'-'0','K'-'0','A'-'0','T'-'0' ; face card score table
DB 3, 8, 8, 9, 0
Input is as a string such as Js3sKsKh
, at pointer in SI
. Output is ZF = 0 and SF = OF
(test with JG
) if player 1 wins, SF ≠ OF
(test with JL
) if player 2 wins or ZF
(test with JE
) if a draw.
Output using DOS test program:
Download and test MODTEN.COM for DOS.
$endgroup$
add a comment |
$begingroup$
x86-16 Assembly, 87 83 bytes
Binary:
00000000: e807 0050 e803 005a 3ac2 ad2c 3092 ad2c ...P...Z:..,0..,
00000010: 30bb 3501 3af4 7503 bb3f 01e8 0a00 92e8 0.5.:.u..?......
00000020: 0600 f6e2 d40a d7c3 b106 bf49 01f2 aee3 ...........I....
00000030: 038a 4504 c312 0a10 0611 0c0f 0a0e 070d ..E.............
00000040: 030b 020b 0509 0408 0124 1a21 1b11 0003 .........$.!....
00000050: 0808 09 ...
Unassembled:
E8 010A CALL GET_HAND ; score first hand, ranked score into AL
50 PUSH AX ; save score
E8 010A CALL GET_HAND ; score second hand
5A POP DX ; restore first hand into DL
3A C2 CMP AL, DL ; compare scores - result in CF, OF and ZF
GET_HAND PROC ; 4 char string to ranked score ("9s7c" -> 6)
AD LODSW ; load first card string
2C 30 SUB AL, '0' ; ASCII convert
92 XCHG DX, AX ; store in DX
AD LODSW ; load second card string
2C 30 SUB AL, '0' ; ASCII convert
BB 0139 MOV BX, OFFSET R ; first, point to non-suited table
3A F4 CMP DH, AH ; is it suited?
75 03 JNZ NO_SUIT
BB 0143 MOV BX, OFFSET RS ; point to suited table
NO_SUIT:
E8 012C CALL GET_VALUE ; get face card value in AL
92 XCHG DX, AX ; swap first and second cards
E8 012C CALL GET_VALUE ; get face card value in AL
F6 E2 MUL DL ; multiply values of two cards
D4 A0 AAM ; AL = AL mod 10
D7 XLAT ; lookup value in rank score table
C3 RET
GET_HAND ENDP
GET_VALUE PROC ; get value of a card (2 -> 2, J -> 3, A -> 9)
B1 06 MOV CL, 6 ; loop counter for scan
BF 014D MOV DI, OFFSET V ; load lookup table
F2/ AE REPNZ SCASB ; scan until match is found
E3 03 JCXZ NOT_FOUND ; if not found, keep original numeric value
8A 45 04 MOV AL, BYTE PTR[DI+4] ; if found, get corresponding value
NOT_FOUND:
C3 RET ; return to program
GET_VALUE ENDP
R DB 18, 10, 16, 6, 17, 12, 15, 10, 14, 7 ; unsuited score table
RS DB 13, 3, 11, 2, 11, 5, 9, 4, 8, 1 ; suited score table
V DB 'J'-'0','Q'-'0','K'-'0','A'-'0','T'-'0' ; face card score table
DB 3, 8, 8, 9, 0
Input is as a string such as Js3sKsKh
, at pointer in SI
. Output is ZF = 0 and SF = OF
(test with JG
) if player 1 wins, SF ≠ OF
(test with JL
) if player 2 wins or ZF
(test with JE
) if a draw.
Output using DOS test program:
Download and test MODTEN.COM for DOS.
$endgroup$
add a comment |
$begingroup$
x86-16 Assembly, 87 83 bytes
Binary:
00000000: e807 0050 e803 005a 3ac2 ad2c 3092 ad2c ...P...Z:..,0..,
00000010: 30bb 3501 3af4 7503 bb3f 01e8 0a00 92e8 0.5.:.u..?......
00000020: 0600 f6e2 d40a d7c3 b106 bf49 01f2 aee3 ...........I....
00000030: 038a 4504 c312 0a10 0611 0c0f 0a0e 070d ..E.............
00000040: 030b 020b 0509 0408 0124 1a21 1b11 0003 .........$.!....
00000050: 0808 09 ...
Unassembled:
E8 010A CALL GET_HAND ; score first hand, ranked score into AL
50 PUSH AX ; save score
E8 010A CALL GET_HAND ; score second hand
5A POP DX ; restore first hand into DL
3A C2 CMP AL, DL ; compare scores - result in CF, OF and ZF
GET_HAND PROC ; 4 char string to ranked score ("9s7c" -> 6)
AD LODSW ; load first card string
2C 30 SUB AL, '0' ; ASCII convert
92 XCHG DX, AX ; store in DX
AD LODSW ; load second card string
2C 30 SUB AL, '0' ; ASCII convert
BB 0139 MOV BX, OFFSET R ; first, point to non-suited table
3A F4 CMP DH, AH ; is it suited?
75 03 JNZ NO_SUIT
BB 0143 MOV BX, OFFSET RS ; point to suited table
NO_SUIT:
E8 012C CALL GET_VALUE ; get face card value in AL
92 XCHG DX, AX ; swap first and second cards
E8 012C CALL GET_VALUE ; get face card value in AL
F6 E2 MUL DL ; multiply values of two cards
D4 A0 AAM ; AL = AL mod 10
D7 XLAT ; lookup value in rank score table
C3 RET
GET_HAND ENDP
GET_VALUE PROC ; get value of a card (2 -> 2, J -> 3, A -> 9)
B1 06 MOV CL, 6 ; loop counter for scan
BF 014D MOV DI, OFFSET V ; load lookup table
F2/ AE REPNZ SCASB ; scan until match is found
E3 03 JCXZ NOT_FOUND ; if not found, keep original numeric value
8A 45 04 MOV AL, BYTE PTR[DI+4] ; if found, get corresponding value
NOT_FOUND:
C3 RET ; return to program
GET_VALUE ENDP
R DB 18, 10, 16, 6, 17, 12, 15, 10, 14, 7 ; unsuited score table
RS DB 13, 3, 11, 2, 11, 5, 9, 4, 8, 1 ; suited score table
V DB 'J'-'0','Q'-'0','K'-'0','A'-'0','T'-'0' ; face card score table
DB 3, 8, 8, 9, 0
Input is as a string such as Js3sKsKh
, at pointer in SI
. Output is ZF = 0 and SF = OF
(test with JG
) if player 1 wins, SF ≠ OF
(test with JL
) if player 2 wins or ZF
(test with JE
) if a draw.
Output using DOS test program:
Download and test MODTEN.COM for DOS.
$endgroup$
x86-16 Assembly, 87 83 bytes
Binary:
00000000: e807 0050 e803 005a 3ac2 ad2c 3092 ad2c ...P...Z:..,0..,
00000010: 30bb 3501 3af4 7503 bb3f 01e8 0a00 92e8 0.5.:.u..?......
00000020: 0600 f6e2 d40a d7c3 b106 bf49 01f2 aee3 ...........I....
00000030: 038a 4504 c312 0a10 0611 0c0f 0a0e 070d ..E.............
00000040: 030b 020b 0509 0408 0124 1a21 1b11 0003 .........$.!....
00000050: 0808 09 ...
Unassembled:
E8 010A CALL GET_HAND ; score first hand, ranked score into AL
50 PUSH AX ; save score
E8 010A CALL GET_HAND ; score second hand
5A POP DX ; restore first hand into DL
3A C2 CMP AL, DL ; compare scores - result in CF, OF and ZF
GET_HAND PROC ; 4 char string to ranked score ("9s7c" -> 6)
AD LODSW ; load first card string
2C 30 SUB AL, '0' ; ASCII convert
92 XCHG DX, AX ; store in DX
AD LODSW ; load second card string
2C 30 SUB AL, '0' ; ASCII convert
BB 0139 MOV BX, OFFSET R ; first, point to non-suited table
3A F4 CMP DH, AH ; is it suited?
75 03 JNZ NO_SUIT
BB 0143 MOV BX, OFFSET RS ; point to suited table
NO_SUIT:
E8 012C CALL GET_VALUE ; get face card value in AL
92 XCHG DX, AX ; swap first and second cards
E8 012C CALL GET_VALUE ; get face card value in AL
F6 E2 MUL DL ; multiply values of two cards
D4 A0 AAM ; AL = AL mod 10
D7 XLAT ; lookup value in rank score table
C3 RET
GET_HAND ENDP
GET_VALUE PROC ; get value of a card (2 -> 2, J -> 3, A -> 9)
B1 06 MOV CL, 6 ; loop counter for scan
BF 014D MOV DI, OFFSET V ; load lookup table
F2/ AE REPNZ SCASB ; scan until match is found
E3 03 JCXZ NOT_FOUND ; if not found, keep original numeric value
8A 45 04 MOV AL, BYTE PTR[DI+4] ; if found, get corresponding value
NOT_FOUND:
C3 RET ; return to program
GET_VALUE ENDP
R DB 18, 10, 16, 6, 17, 12, 15, 10, 14, 7 ; unsuited score table
RS DB 13, 3, 11, 2, 11, 5, 9, 4, 8, 1 ; suited score table
V DB 'J'-'0','Q'-'0','K'-'0','A'-'0','T'-'0' ; face card score table
DB 3, 8, 8, 9, 0
Input is as a string such as Js3sKsKh
, at pointer in SI
. Output is ZF = 0 and SF = OF
(test with JG
) if player 1 wins, SF ≠ OF
(test with JL
) if player 2 wins or ZF
(test with JE
) if a draw.
Output using DOS test program:
Download and test MODTEN.COM for DOS.
edited yesterday
answered yesterday
640KB640KB
4,7811 gold badge11 silver badges30 bronze badges
4,7811 gold badge11 silver badges30 bronze badges
add a comment |
add a comment |
$begingroup$
05AB1E, 41 bytes
•V›{₆Ÿ&∊WÍj¸•19вIεø`ËT*s"JTQKA"Ž_Y‡Pθ+}èÆ
Input as a list of list of list of characters, like the third example input format in the challenge description. I.e. P1 7c Qh
& P2 8s Ks
would be input as [[["7","c"],["Q","h"]],[["8","s"],["K","s"]]]
. (And uses T
for 10
.)
Outputs a negative integer if player 1 wins; a positive integer if player 2 wins; or 0 if it's a draw.
Try it online or verify all test cases.
Explanation:
•V›{₆Ÿ&∊WÍj¸• # Push compressed integer 36742512464916394906012008
19в # Convert it to base-19 as list:
# [18,10,16,6,17,12,15,10,14,7,13,3,11,2,11,5,9,4,8,1]
Iε # Push the input, and map each of its hands to:
ø # Zip/transpose the hand; swapping rows/columns
# i.e. [["8","s"],["K","s"]] → [[["8","K"],["s","s"]]
` # Push them separated to the stack
Ë # Check if the two suits in the top list are equal (1/0 for truthy/falsey)
T* # Multiply that by 10 (so we now have 10 if the suits are equal; 0 if not)
s # Swap to get the list with the two values
"JTQKA" # Push string "JTQKA"
Ž_Y # Push compressed integer 30889
‡ # Transliterate these characters to these digits
P # Now take the product of the two values in the list
θ # Only leave the last digit (basically modulo-10)
+ # And add it to the 0/10
# (now we have the hand values of both players,
# where instead of a trailing "s" we have a leading 1)
}è # After the map: index each value into the earlier created integer-list
# (now we have the hand rank of both players)
Æ # And then reduce the resulting integers by subtracting
# (after which the result is output implicitly)
See this 05AB1E tip of mine (sections How to compress large integers? and How to compress integer lists?) to understand why •V›{₆Ÿ&∊WÍj¸•
is 36742512464916394906012008
, •V›{₆Ÿ&∊WÍj¸•19в
is [18,10,16,6,17,12,15,10,14,7,13,3,11,2,11,5,9,4,8,1]
and Ž_Y
is 30889
.
PS: "JTQKA"
could alternatively be .•∞ú₄•u
, but unfortunately it's the same byte-count. Only lowercase (non-dictionary) strings can be compressed in 05AB1E.
$endgroup$
add a comment |
$begingroup$
05AB1E, 41 bytes
•V›{₆Ÿ&∊WÍj¸•19вIεø`ËT*s"JTQKA"Ž_Y‡Pθ+}èÆ
Input as a list of list of list of characters, like the third example input format in the challenge description. I.e. P1 7c Qh
& P2 8s Ks
would be input as [[["7","c"],["Q","h"]],[["8","s"],["K","s"]]]
. (And uses T
for 10
.)
Outputs a negative integer if player 1 wins; a positive integer if player 2 wins; or 0 if it's a draw.
Try it online or verify all test cases.
Explanation:
•V›{₆Ÿ&∊WÍj¸• # Push compressed integer 36742512464916394906012008
19в # Convert it to base-19 as list:
# [18,10,16,6,17,12,15,10,14,7,13,3,11,2,11,5,9,4,8,1]
Iε # Push the input, and map each of its hands to:
ø # Zip/transpose the hand; swapping rows/columns
# i.e. [["8","s"],["K","s"]] → [[["8","K"],["s","s"]]
` # Push them separated to the stack
Ë # Check if the two suits in the top list are equal (1/0 for truthy/falsey)
T* # Multiply that by 10 (so we now have 10 if the suits are equal; 0 if not)
s # Swap to get the list with the two values
"JTQKA" # Push string "JTQKA"
Ž_Y # Push compressed integer 30889
‡ # Transliterate these characters to these digits
P # Now take the product of the two values in the list
θ # Only leave the last digit (basically modulo-10)
+ # And add it to the 0/10
# (now we have the hand values of both players,
# where instead of a trailing "s" we have a leading 1)
}è # After the map: index each value into the earlier created integer-list
# (now we have the hand rank of both players)
Æ # And then reduce the resulting integers by subtracting
# (after which the result is output implicitly)
See this 05AB1E tip of mine (sections How to compress large integers? and How to compress integer lists?) to understand why •V›{₆Ÿ&∊WÍj¸•
is 36742512464916394906012008
, •V›{₆Ÿ&∊WÍj¸•19в
is [18,10,16,6,17,12,15,10,14,7,13,3,11,2,11,5,9,4,8,1]
and Ž_Y
is 30889
.
PS: "JTQKA"
could alternatively be .•∞ú₄•u
, but unfortunately it's the same byte-count. Only lowercase (non-dictionary) strings can be compressed in 05AB1E.
$endgroup$
add a comment |
$begingroup$
05AB1E, 41 bytes
•V›{₆Ÿ&∊WÍj¸•19вIεø`ËT*s"JTQKA"Ž_Y‡Pθ+}èÆ
Input as a list of list of list of characters, like the third example input format in the challenge description. I.e. P1 7c Qh
& P2 8s Ks
would be input as [[["7","c"],["Q","h"]],[["8","s"],["K","s"]]]
. (And uses T
for 10
.)
Outputs a negative integer if player 1 wins; a positive integer if player 2 wins; or 0 if it's a draw.
Try it online or verify all test cases.
Explanation:
•V›{₆Ÿ&∊WÍj¸• # Push compressed integer 36742512464916394906012008
19в # Convert it to base-19 as list:
# [18,10,16,6,17,12,15,10,14,7,13,3,11,2,11,5,9,4,8,1]
Iε # Push the input, and map each of its hands to:
ø # Zip/transpose the hand; swapping rows/columns
# i.e. [["8","s"],["K","s"]] → [[["8","K"],["s","s"]]
` # Push them separated to the stack
Ë # Check if the two suits in the top list are equal (1/0 for truthy/falsey)
T* # Multiply that by 10 (so we now have 10 if the suits are equal; 0 if not)
s # Swap to get the list with the two values
"JTQKA" # Push string "JTQKA"
Ž_Y # Push compressed integer 30889
‡ # Transliterate these characters to these digits
P # Now take the product of the two values in the list
θ # Only leave the last digit (basically modulo-10)
+ # And add it to the 0/10
# (now we have the hand values of both players,
# where instead of a trailing "s" we have a leading 1)
}è # After the map: index each value into the earlier created integer-list
# (now we have the hand rank of both players)
Æ # And then reduce the resulting integers by subtracting
# (after which the result is output implicitly)
See this 05AB1E tip of mine (sections How to compress large integers? and How to compress integer lists?) to understand why •V›{₆Ÿ&∊WÍj¸•
is 36742512464916394906012008
, •V›{₆Ÿ&∊WÍj¸•19в
is [18,10,16,6,17,12,15,10,14,7,13,3,11,2,11,5,9,4,8,1]
and Ž_Y
is 30889
.
PS: "JTQKA"
could alternatively be .•∞ú₄•u
, but unfortunately it's the same byte-count. Only lowercase (non-dictionary) strings can be compressed in 05AB1E.
$endgroup$
05AB1E, 41 bytes
•V›{₆Ÿ&∊WÍj¸•19вIεø`ËT*s"JTQKA"Ž_Y‡Pθ+}èÆ
Input as a list of list of list of characters, like the third example input format in the challenge description. I.e. P1 7c Qh
& P2 8s Ks
would be input as [[["7","c"],["Q","h"]],[["8","s"],["K","s"]]]
. (And uses T
for 10
.)
Outputs a negative integer if player 1 wins; a positive integer if player 2 wins; or 0 if it's a draw.
Try it online or verify all test cases.
Explanation:
•V›{₆Ÿ&∊WÍj¸• # Push compressed integer 36742512464916394906012008
19в # Convert it to base-19 as list:
# [18,10,16,6,17,12,15,10,14,7,13,3,11,2,11,5,9,4,8,1]
Iε # Push the input, and map each of its hands to:
ø # Zip/transpose the hand; swapping rows/columns
# i.e. [["8","s"],["K","s"]] → [[["8","K"],["s","s"]]
` # Push them separated to the stack
Ë # Check if the two suits in the top list are equal (1/0 for truthy/falsey)
T* # Multiply that by 10 (so we now have 10 if the suits are equal; 0 if not)
s # Swap to get the list with the two values
"JTQKA" # Push string "JTQKA"
Ž_Y # Push compressed integer 30889
‡ # Transliterate these characters to these digits
P # Now take the product of the two values in the list
θ # Only leave the last digit (basically modulo-10)
+ # And add it to the 0/10
# (now we have the hand values of both players,
# where instead of a trailing "s" we have a leading 1)
}è # After the map: index each value into the earlier created integer-list
# (now we have the hand rank of both players)
Æ # And then reduce the resulting integers by subtracting
# (after which the result is output implicitly)
See this 05AB1E tip of mine (sections How to compress large integers? and How to compress integer lists?) to understand why •V›{₆Ÿ&∊WÍj¸•
is 36742512464916394906012008
, •V›{₆Ÿ&∊WÍj¸•19в
is [18,10,16,6,17,12,15,10,14,7,13,3,11,2,11,5,9,4,8,1]
and Ž_Y
is 30889
.
PS: "JTQKA"
could alternatively be .•∞ú₄•u
, but unfortunately it's the same byte-count. Only lowercase (non-dictionary) strings can be compressed in 05AB1E.
edited yesterday
answered yesterday
Kevin CruijssenKevin Cruijssen
50.4k7 gold badges84 silver badges246 bronze badges
50.4k7 gold badges84 silver badges246 bronze badges
add a comment |
add a comment |
$begingroup$
PHP, 212 185 178 149 bytes
while($p=$argv[++$x])$$x=ord(rjpfqlojngmckbkeidha[(($v=[J=>3,Q=>8,K=>8,A=>9])[$p[0]]?:$p[0])*($v[$p[2]]?:$p[2])%10+($p[1]==$p[3])*10]);echo${1}-${2};
Try it online!
- -7 bytes thanks to @Night2!
- -29 bytes by ASCII encoding the table instead of array
Input is via command line. Output to STDOUT
is negative if player 1 wins, positive if player 2 wins, 0
if tie. Example:
$ php modten.php Js3s KsKh
-1
$endgroup$
1
$begingroup$
@Night2 I suppose if I was willing to give us the spaceship operator (I mean, how often do you get to use that?), I could -2 bytes and just return negative, positive or zero, instead of-1
,1
or0
.
$endgroup$
– 640KB
9 hours ago
$begingroup$
I was amazed (in a good way) to see the spaceship operator in previous answer.
$endgroup$
– Night2
9 hours ago
add a comment |
$begingroup$
PHP, 212 185 178 149 bytes
while($p=$argv[++$x])$$x=ord(rjpfqlojngmckbkeidha[(($v=[J=>3,Q=>8,K=>8,A=>9])[$p[0]]?:$p[0])*($v[$p[2]]?:$p[2])%10+($p[1]==$p[3])*10]);echo${1}-${2};
Try it online!
- -7 bytes thanks to @Night2!
- -29 bytes by ASCII encoding the table instead of array
Input is via command line. Output to STDOUT
is negative if player 1 wins, positive if player 2 wins, 0
if tie. Example:
$ php modten.php Js3s KsKh
-1
$endgroup$
1
$begingroup$
@Night2 I suppose if I was willing to give us the spaceship operator (I mean, how often do you get to use that?), I could -2 bytes and just return negative, positive or zero, instead of-1
,1
or0
.
$endgroup$
– 640KB
9 hours ago
$begingroup$
I was amazed (in a good way) to see the spaceship operator in previous answer.
$endgroup$
– Night2
9 hours ago
add a comment |
$begingroup$
PHP, 212 185 178 149 bytes
while($p=$argv[++$x])$$x=ord(rjpfqlojngmckbkeidha[(($v=[J=>3,Q=>8,K=>8,A=>9])[$p[0]]?:$p[0])*($v[$p[2]]?:$p[2])%10+($p[1]==$p[3])*10]);echo${1}-${2};
Try it online!
- -7 bytes thanks to @Night2!
- -29 bytes by ASCII encoding the table instead of array
Input is via command line. Output to STDOUT
is negative if player 1 wins, positive if player 2 wins, 0
if tie. Example:
$ php modten.php Js3s KsKh
-1
$endgroup$
PHP, 212 185 178 149 bytes
while($p=$argv[++$x])$$x=ord(rjpfqlojngmckbkeidha[(($v=[J=>3,Q=>8,K=>8,A=>9])[$p[0]]?:$p[0])*($v[$p[2]]?:$p[2])%10+($p[1]==$p[3])*10]);echo${1}-${2};
Try it online!
- -7 bytes thanks to @Night2!
- -29 bytes by ASCII encoding the table instead of array
Input is via command line. Output to STDOUT
is negative if player 1 wins, positive if player 2 wins, 0
if tie. Example:
$ php modten.php Js3s KsKh
-1
edited 9 hours ago
answered yesterday
640KB640KB
4,7811 gold badge11 silver badges30 bronze badges
4,7811 gold badge11 silver badges30 bronze badges
1
$begingroup$
@Night2 I suppose if I was willing to give us the spaceship operator (I mean, how often do you get to use that?), I could -2 bytes and just return negative, positive or zero, instead of-1
,1
or0
.
$endgroup$
– 640KB
9 hours ago
$begingroup$
I was amazed (in a good way) to see the spaceship operator in previous answer.
$endgroup$
– Night2
9 hours ago
add a comment |
1
$begingroup$
@Night2 I suppose if I was willing to give us the spaceship operator (I mean, how often do you get to use that?), I could -2 bytes and just return negative, positive or zero, instead of-1
,1
or0
.
$endgroup$
– 640KB
9 hours ago
$begingroup$
I was amazed (in a good way) to see the spaceship operator in previous answer.
$endgroup$
– Night2
9 hours ago
1
1
$begingroup$
@Night2 I suppose if I was willing to give us the spaceship operator (I mean, how often do you get to use that?), I could -2 bytes and just return negative, positive or zero, instead of
-1
, 1
or 0
.$endgroup$
– 640KB
9 hours ago
$begingroup$
@Night2 I suppose if I was willing to give us the spaceship operator (I mean, how often do you get to use that?), I could -2 bytes and just return negative, positive or zero, instead of
-1
, 1
or 0
.$endgroup$
– 640KB
9 hours ago
$begingroup$
I was amazed (in a good way) to see the spaceship operator in previous answer.
$endgroup$
– Night2
9 hours ago
$begingroup$
I was amazed (in a good way) to see the spaceship operator in previous answer.
$endgroup$
– Night2
9 hours ago
add a comment |
$begingroup$
C (gcc), 172 167 165 164 bytes
p(l,v)char*l,*v;{v="T 23456789 J QA K";return"A<92?:51@:;4>893=760"[(l[1]==l[3])+(index(v,l[2])-v)*(index(v,*l)-v)%10*2];}f(char*s){return p(s+5)-p(s);}
Try it online!
2 bytes shaved off thanks to @ceilingcat!
Basically a port of @Joel's Python3 solution, but without the base18 encoding. Expects the input as one string with a space separating the hands of the two players, and outputs an integer that is positive, negative or zero to indicate player 1 wins, player 2 wins or if it's a draw.
$endgroup$
add a comment |
$begingroup$
C (gcc), 172 167 165 164 bytes
p(l,v)char*l,*v;{v="T 23456789 J QA K";return"A<92?:51@:;4>893=760"[(l[1]==l[3])+(index(v,l[2])-v)*(index(v,*l)-v)%10*2];}f(char*s){return p(s+5)-p(s);}
Try it online!
2 bytes shaved off thanks to @ceilingcat!
Basically a port of @Joel's Python3 solution, but without the base18 encoding. Expects the input as one string with a space separating the hands of the two players, and outputs an integer that is positive, negative or zero to indicate player 1 wins, player 2 wins or if it's a draw.
$endgroup$
add a comment |
$begingroup$
C (gcc), 172 167 165 164 bytes
p(l,v)char*l,*v;{v="T 23456789 J QA K";return"A<92?:51@:;4>893=760"[(l[1]==l[3])+(index(v,l[2])-v)*(index(v,*l)-v)%10*2];}f(char*s){return p(s+5)-p(s);}
Try it online!
2 bytes shaved off thanks to @ceilingcat!
Basically a port of @Joel's Python3 solution, but without the base18 encoding. Expects the input as one string with a space separating the hands of the two players, and outputs an integer that is positive, negative or zero to indicate player 1 wins, player 2 wins or if it's a draw.
$endgroup$
C (gcc), 172 167 165 164 bytes
p(l,v)char*l,*v;{v="T 23456789 J QA K";return"A<92?:51@:;4>893=760"[(l[1]==l[3])+(index(v,l[2])-v)*(index(v,*l)-v)%10*2];}f(char*s){return p(s+5)-p(s);}
Try it online!
2 bytes shaved off thanks to @ceilingcat!
Basically a port of @Joel's Python3 solution, but without the base18 encoding. Expects the input as one string with a space separating the hands of the two players, and outputs an integer that is positive, negative or zero to indicate player 1 wins, player 2 wins or if it's a draw.
edited yesterday
answered yesterday
G. SliepenG. Sliepen
4892 silver badges6 bronze badges
4892 silver badges6 bronze badges
add a comment |
add a comment |
$begingroup$
Perl 6, 101 100 94 88 bytes
-1 byte thanks to Jo King
{[-] .map:{'HC92FA51GAB4E893D76'.ords[[*](.[*;0]>>.&{TR/JQKA/3889/})%10*2+[eq] .[*;1]]}}
Try it online!
Takes input as f(((<J ♠>, <3 ♠>), (<10 ♠>, <K ♥>)))
using 10
for Ten. Returns a value < 0 if player 1 wins, > 0 if player 2 wins, 0 if it's a draw.
Explanation
{
[-] # subtract values
.map:{ # map both hands
'HC92FA51GAB4E893D76'.ords[ # lookup rank in code point array
[*]( # multiply
.[*;0] # card ranks
>>.&{TR/JQKA/3889/} # translate J,Q,K,A to 3,8,8,9
)
%10*2 # mod 10 times 2
+[eq] .[*;1] # plus 1 if suited
]
}
}
$endgroup$
add a comment |
$begingroup$
Perl 6, 101 100 94 88 bytes
-1 byte thanks to Jo King
{[-] .map:{'HC92FA51GAB4E893D76'.ords[[*](.[*;0]>>.&{TR/JQKA/3889/})%10*2+[eq] .[*;1]]}}
Try it online!
Takes input as f(((<J ♠>, <3 ♠>), (<10 ♠>, <K ♥>)))
using 10
for Ten. Returns a value < 0 if player 1 wins, > 0 if player 2 wins, 0 if it's a draw.
Explanation
{
[-] # subtract values
.map:{ # map both hands
'HC92FA51GAB4E893D76'.ords[ # lookup rank in code point array
[*]( # multiply
.[*;0] # card ranks
>>.&{TR/JQKA/3889/} # translate J,Q,K,A to 3,8,8,9
)
%10*2 # mod 10 times 2
+[eq] .[*;1] # plus 1 if suited
]
}
}
$endgroup$
add a comment |
$begingroup$
Perl 6, 101 100 94 88 bytes
-1 byte thanks to Jo King
{[-] .map:{'HC92FA51GAB4E893D76'.ords[[*](.[*;0]>>.&{TR/JQKA/3889/})%10*2+[eq] .[*;1]]}}
Try it online!
Takes input as f(((<J ♠>, <3 ♠>), (<10 ♠>, <K ♥>)))
using 10
for Ten. Returns a value < 0 if player 1 wins, > 0 if player 2 wins, 0 if it's a draw.
Explanation
{
[-] # subtract values
.map:{ # map both hands
'HC92FA51GAB4E893D76'.ords[ # lookup rank in code point array
[*]( # multiply
.[*;0] # card ranks
>>.&{TR/JQKA/3889/} # translate J,Q,K,A to 3,8,8,9
)
%10*2 # mod 10 times 2
+[eq] .[*;1] # plus 1 if suited
]
}
}
$endgroup$
Perl 6, 101 100 94 88 bytes
-1 byte thanks to Jo King
{[-] .map:{'HC92FA51GAB4E893D76'.ords[[*](.[*;0]>>.&{TR/JQKA/3889/})%10*2+[eq] .[*;1]]}}
Try it online!
Takes input as f(((<J ♠>, <3 ♠>), (<10 ♠>, <K ♥>)))
using 10
for Ten. Returns a value < 0 if player 1 wins, > 0 if player 2 wins, 0 if it's a draw.
Explanation
{
[-] # subtract values
.map:{ # map both hands
'HC92FA51GAB4E893D76'.ords[ # lookup rank in code point array
[*]( # multiply
.[*;0] # card ranks
>>.&{TR/JQKA/3889/} # translate J,Q,K,A to 3,8,8,9
)
%10*2 # mod 10 times 2
+[eq] .[*;1] # plus 1 if suited
]
}
}
edited 7 hours ago
answered yesterday
nwellnhofnwellnhof
8,1101 gold badge12 silver badges29 bronze badges
8,1101 gold badge12 silver badges29 bronze badges
add a comment |
add a comment |
$begingroup$
Jelly, 46 bytes
“T0J3Q8K8A9”yⱮZV€P$Eƭ€)%⁵UḌị“©N¿!Æßvṅ?żṀ’b18¤I
Try it online!
A full program taking as its argument for example ["7h","Ks"],["4s","Ts"]
and printing zero if both players draw, positive if player 1 wins and negative if player 2 wins.
$endgroup$
add a comment |
$begingroup$
Jelly, 46 bytes
“T0J3Q8K8A9”yⱮZV€P$Eƭ€)%⁵UḌị“©N¿!Æßvṅ?żṀ’b18¤I
Try it online!
A full program taking as its argument for example ["7h","Ks"],["4s","Ts"]
and printing zero if both players draw, positive if player 1 wins and negative if player 2 wins.
$endgroup$
add a comment |
$begingroup$
Jelly, 46 bytes
“T0J3Q8K8A9”yⱮZV€P$Eƭ€)%⁵UḌị“©N¿!Æßvṅ?żṀ’b18¤I
Try it online!
A full program taking as its argument for example ["7h","Ks"],["4s","Ts"]
and printing zero if both players draw, positive if player 1 wins and negative if player 2 wins.
$endgroup$
Jelly, 46 bytes
“T0J3Q8K8A9”yⱮZV€P$Eƭ€)%⁵UḌị“©N¿!Æßvṅ?żṀ’b18¤I
Try it online!
A full program taking as its argument for example ["7h","Ks"],["4s","Ts"]
and printing zero if both players draw, positive if player 1 wins and negative if player 2 wins.
answered yesterday
Nick KennedyNick Kennedy
6,0771 gold badge9 silver badges15 bronze badges
6,0771 gold badge9 silver badges15 bronze badges
add a comment |
add a comment |
$begingroup$
Charcoal, 97 bytes
≔”)¶&sNψU↓”ζF¹³F¹³F⁻⁴⁼ικ⊞υ⁺÷λ³⊗﹪Π⁺§ζι§ζκχ≔”A↘τ[⁵PkxτG”ε≔⁰δF⟦θη⟧≦⁻№υ⁺⁼§ι¹§ι³⊗﹪Π⁺§ζ⌕ε§ι⁰§ζ⌕ε§ι²χδIδ
Try it online! Link is to verbose version of code. Takes input as two strings of 4 characters e.g. QcKc
6d4d
and outputs a signed integer. Explanation:
≔”)¶&sNψU↓”ζ
Compressed string 2345678903889
represents the card values.
F¹³F¹³
Loop over each possible pair of values.
F⁻⁴⁼ικ
Loop over each possible second card suit. Without loss of generality we can assume that the first card has suit 3, so the second card suit can range from 0 to 3 unless the values are the same in which case it can only range from 0 to 2.
⊞υ⁺÷λ³⊗﹪Π⁺§ζι§ζκχ
Compute the modified score of the hand, which is the value of the hand doubled, plus 1 if the suits are the same (i.e. the second card has suit 3).
≔”A↘τ[⁵PkxτG”ε
Compressed string 23456789TJQKA
represents the card characters. The input cards are looked up in this string and then the position is used to index into the first string to get the card's value.
≔⁰δ
Initialise the result to 0.
F⟦θη⟧
Loop over the two hands.
≦⁻№υ⁺⁼§ι¹§ι³⊗﹪Π⁺§ζ⌕ε§ι⁰§ζ⌕ε§ι²χδ
Calculate the modified score of the hand, and thus its frequency, and subtract the result from this.
Iδ
Output the frequency difference.
$endgroup$
add a comment |
$begingroup$
Charcoal, 97 bytes
≔”)¶&sNψU↓”ζF¹³F¹³F⁻⁴⁼ικ⊞υ⁺÷λ³⊗﹪Π⁺§ζι§ζκχ≔”A↘τ[⁵PkxτG”ε≔⁰δF⟦θη⟧≦⁻№υ⁺⁼§ι¹§ι³⊗﹪Π⁺§ζ⌕ε§ι⁰§ζ⌕ε§ι²χδIδ
Try it online! Link is to verbose version of code. Takes input as two strings of 4 characters e.g. QcKc
6d4d
and outputs a signed integer. Explanation:
≔”)¶&sNψU↓”ζ
Compressed string 2345678903889
represents the card values.
F¹³F¹³
Loop over each possible pair of values.
F⁻⁴⁼ικ
Loop over each possible second card suit. Without loss of generality we can assume that the first card has suit 3, so the second card suit can range from 0 to 3 unless the values are the same in which case it can only range from 0 to 2.
⊞υ⁺÷λ³⊗﹪Π⁺§ζι§ζκχ
Compute the modified score of the hand, which is the value of the hand doubled, plus 1 if the suits are the same (i.e. the second card has suit 3).
≔”A↘τ[⁵PkxτG”ε
Compressed string 23456789TJQKA
represents the card characters. The input cards are looked up in this string and then the position is used to index into the first string to get the card's value.
≔⁰δ
Initialise the result to 0.
F⟦θη⟧
Loop over the two hands.
≦⁻№υ⁺⁼§ι¹§ι³⊗﹪Π⁺§ζ⌕ε§ι⁰§ζ⌕ε§ι²χδ
Calculate the modified score of the hand, and thus its frequency, and subtract the result from this.
Iδ
Output the frequency difference.
$endgroup$
add a comment |
$begingroup$
Charcoal, 97 bytes
≔”)¶&sNψU↓”ζF¹³F¹³F⁻⁴⁼ικ⊞υ⁺÷λ³⊗﹪Π⁺§ζι§ζκχ≔”A↘τ[⁵PkxτG”ε≔⁰δF⟦θη⟧≦⁻№υ⁺⁼§ι¹§ι³⊗﹪Π⁺§ζ⌕ε§ι⁰§ζ⌕ε§ι²χδIδ
Try it online! Link is to verbose version of code. Takes input as two strings of 4 characters e.g. QcKc
6d4d
and outputs a signed integer. Explanation:
≔”)¶&sNψU↓”ζ
Compressed string 2345678903889
represents the card values.
F¹³F¹³
Loop over each possible pair of values.
F⁻⁴⁼ικ
Loop over each possible second card suit. Without loss of generality we can assume that the first card has suit 3, so the second card suit can range from 0 to 3 unless the values are the same in which case it can only range from 0 to 2.
⊞υ⁺÷λ³⊗﹪Π⁺§ζι§ζκχ
Compute the modified score of the hand, which is the value of the hand doubled, plus 1 if the suits are the same (i.e. the second card has suit 3).
≔”A↘τ[⁵PkxτG”ε
Compressed string 23456789TJQKA
represents the card characters. The input cards are looked up in this string and then the position is used to index into the first string to get the card's value.
≔⁰δ
Initialise the result to 0.
F⟦θη⟧
Loop over the two hands.
≦⁻№υ⁺⁼§ι¹§ι³⊗﹪Π⁺§ζ⌕ε§ι⁰§ζ⌕ε§ι²χδ
Calculate the modified score of the hand, and thus its frequency, and subtract the result from this.
Iδ
Output the frequency difference.
$endgroup$
Charcoal, 97 bytes
≔”)¶&sNψU↓”ζF¹³F¹³F⁻⁴⁼ικ⊞υ⁺÷λ³⊗﹪Π⁺§ζι§ζκχ≔”A↘τ[⁵PkxτG”ε≔⁰δF⟦θη⟧≦⁻№υ⁺⁼§ι¹§ι³⊗﹪Π⁺§ζ⌕ε§ι⁰§ζ⌕ε§ι²χδIδ
Try it online! Link is to verbose version of code. Takes input as two strings of 4 characters e.g. QcKc
6d4d
and outputs a signed integer. Explanation:
≔”)¶&sNψU↓”ζ
Compressed string 2345678903889
represents the card values.
F¹³F¹³
Loop over each possible pair of values.
F⁻⁴⁼ικ
Loop over each possible second card suit. Without loss of generality we can assume that the first card has suit 3, so the second card suit can range from 0 to 3 unless the values are the same in which case it can only range from 0 to 2.
⊞υ⁺÷λ³⊗﹪Π⁺§ζι§ζκχ
Compute the modified score of the hand, which is the value of the hand doubled, plus 1 if the suits are the same (i.e. the second card has suit 3).
≔”A↘τ[⁵PkxτG”ε
Compressed string 23456789TJQKA
represents the card characters. The input cards are looked up in this string and then the position is used to index into the first string to get the card's value.
≔⁰δ
Initialise the result to 0.
F⟦θη⟧
Loop over the two hands.
≦⁻№υ⁺⁼§ι¹§ι³⊗﹪Π⁺§ζ⌕ε§ι⁰§ζ⌕ε§ι²χδ
Calculate the modified score of the hand, and thus its frequency, and subtract the result from this.
Iδ
Output the frequency difference.
answered yesterday
NeilNeil
87.9k8 gold badges46 silver badges185 bronze badges
87.9k8 gold badges46 silver badges185 bronze badges
add a comment |
add a comment |
$begingroup$
C# (Visual C# Interactive Compiler), 139 bytes
x=>x.Sum(n=>(i++%2*2-1)*(n[1]==n[3]?"":" ")[n.Aggregate(1,(a,b)=>a*(b>85?1:b>83?0:b>74?8:b>73?3:b>64?9:b-48))%10]);int i
Try it online!
$endgroup$
add a comment |
$begingroup$
C# (Visual C# Interactive Compiler), 139 bytes
x=>x.Sum(n=>(i++%2*2-1)*(n[1]==n[3]?"":" ")[n.Aggregate(1,(a,b)=>a*(b>85?1:b>83?0:b>74?8:b>73?3:b>64?9:b-48))%10]);int i
Try it online!
$endgroup$
add a comment |
$begingroup$
C# (Visual C# Interactive Compiler), 139 bytes
x=>x.Sum(n=>(i++%2*2-1)*(n[1]==n[3]?"":" ")[n.Aggregate(1,(a,b)=>a*(b>85?1:b>83?0:b>74?8:b>73?3:b>64?9:b-48))%10]);int i
Try it online!
$endgroup$
C# (Visual C# Interactive Compiler), 139 bytes
x=>x.Sum(n=>(i++%2*2-1)*(n[1]==n[3]?"":" ")[n.Aggregate(1,(a,b)=>a*(b>85?1:b>83?0:b>74?8:b>73?3:b>64?9:b-48))%10]);int i
Try it online!
answered 23 hours ago
Embodiment of IgnoranceEmbodiment of Ignorance
5,1361 silver badge30 bronze badges
5,1361 silver badge30 bronze badges
add a comment |
add a comment |
$begingroup$
Perl 5 -p
, 107 bytes
$a=A;y/ATJQK/90388/;${$a++}=substr"IAG6HCFAE7D3B2B59481",($1eq$3).$&*$2%10,1while/.(.) (.)(.)/g;$_=$A cmp$B
Try it online!
Input:
As 4d,Th 8c
(Actually, the comma can be any character.)
Output:
-1 Player one wins
0 Draw
1 Player two wins
$endgroup$
add a comment |
$begingroup$
Perl 5 -p
, 107 bytes
$a=A;y/ATJQK/90388/;${$a++}=substr"IAG6HCFAE7D3B2B59481",($1eq$3).$&*$2%10,1while/.(.) (.)(.)/g;$_=$A cmp$B
Try it online!
Input:
As 4d,Th 8c
(Actually, the comma can be any character.)
Output:
-1 Player one wins
0 Draw
1 Player two wins
$endgroup$
add a comment |
$begingroup$
Perl 5 -p
, 107 bytes
$a=A;y/ATJQK/90388/;${$a++}=substr"IAG6HCFAE7D3B2B59481",($1eq$3).$&*$2%10,1while/.(.) (.)(.)/g;$_=$A cmp$B
Try it online!
Input:
As 4d,Th 8c
(Actually, the comma can be any character.)
Output:
-1 Player one wins
0 Draw
1 Player two wins
$endgroup$
Perl 5 -p
, 107 bytes
$a=A;y/ATJQK/90388/;${$a++}=substr"IAG6HCFAE7D3B2B59481",($1eq$3).$&*$2%10,1while/.(.) (.)(.)/g;$_=$A cmp$B
Try it online!
Input:
As 4d,Th 8c
(Actually, the comma can be any character.)
Output:
-1 Player one wins
0 Draw
1 Player two wins
edited 23 hours ago
answered 23 hours ago
XcaliXcali
6,7641 gold badge7 silver badges23 bronze badges
6,7641 gold badge7 silver badges23 bronze badges
add a comment |
add a comment |
If this is an answer to a challenge…
…Be sure to follow the challenge specification. However, please refrain from exploiting obvious loopholes. Answers abusing any of the standard loopholes are considered invalid. If you think a specification is unclear or underspecified, comment on the question instead.
…Try to optimize your score. For instance, answers to code-golf challenges should attempt to be as short as possible. You can always include a readable version of the code in addition to the competitive one.
Explanations of your answer make it more interesting to read and are very much encouraged.…Include a short header which indicates the language(s) of your code and its score, as defined by the challenge.
More generally…
…Please make sure to answer the question and provide sufficient detail.
…Avoid asking for help, clarification or responding to other answers (use comments instead).
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f190732%2fnothing-like-a-good-ol-game-of-modten%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
$begingroup$
What about taking enums as input? Haskell has a pretty powerful type system; I'm fairly sure something like this could be made directly in it.
$endgroup$
– wizzwizz4
yesterday
$begingroup$
This isn't Haskell, but would
{{J, s}, {3, s}}
be okay?$endgroup$
– wizzwizz4
yesterday
1
$begingroup$
@wizzwizz4 Yes, that's fine.
$endgroup$
– Arnauld
yesterday
$begingroup$
This might be clearer with "hands of cards with matching suits" instead of "suited cards".
$endgroup$
– chrylis
10 hours ago