10
1
Golf Golf!
This is my first challenge, so please be gentle! The challenge is to write a program that will output the correct score for a layout in the card game "Golf."
The card game Golf has many variations. The house rules I use follow the standard rules for Six-Card Golf given by Pagat, with one slight difference. There is already a similar challenge here but I think this one is more interesting because it requires you to take the orientation of the cards into account.
Each player has a 2x3 layout of cards. By the end of each round all cards are turned face up and scored as follows:
- Each ace counts 1 point.
- Each two counts minus two points.
- Each numeral card from 3 to 10 scores face value.
- Each Jack or Queen scores 10 points.
- Each King scores zero points.
- A pair of equal cards in the same column scores zero points for the column (even if the equal cards are twos).
- A set of three equal cards in the same row scores zero points for the row (even if the equal cards are twos).
Input
The input can be a string or array of any kind.
Output
An integer representing the score of the Golf hand.
Examples
These examples use the notation A23456789TJQK
but you need not use that notation in your answer.
Layout
AK3
J23
Score
9
-----------------------
Layout
25Q
25J
Score
20
-----------------------
Layout
T82
T8A
Score
-1
-----------------------
Layout
QQQ
234
Score
5
-----------------------
Layout
TJQ
QTJ
Score
60
-----------------------
Layout
888
382
Score
1
-----------------------
Layout
888
888
Score
0
This is code golf, so the shortest answer in bytes wins!
6Shouldn't the first example score 9? – Jonathan Allan – 2019-09-21T12:23:45.690
2Nice first challenge! As a slight note, the "(even if the equal cards are twos)" parts are unnecessary and slightly confusing in this challenge, since the resulting score isn't compared with other players' scores. Instead, you may want to clarify that the all-equal column and row scores override the individual scores of the cards in their respective column or row. – Erik the Outgolfer – 2019-09-21T12:29:23.667
1"...or array of any kind" - must the content be characters (or may we circumvent the mapping of characters to values)? – Jonathan Allan – 2019-09-21T12:37:14.010
@JonathanAllan Hm, it does say "These examples use the notation
A23456789TJQK
but you need not use that notation in your answer." – Erik the Outgolfer – 2019-09-21T12:41:27.453@EriktheOutgolfer thanks! – Jonathan Allan – 2019-09-21T12:43:27.353
2I'd suggest adding a test case with a column AND a row being equal, like
JJJ 2J2
->-4
. – Jonathan Allan – 2019-09-21T13:40:14.943@JonathanAllan thanks for noticing that error in the first example. I didn't want to specify input format so there is no requirement that the input be characters. – qdread – 2019-09-22T01:31:27.877
I see nothing about how many decks are used (the rules say larger games use multiple decks) so suggested test case of
[5,5,5],[5,5,5] = 0
. Unless we're guaranteed at most 4 of one card? – Veskah – 2019-09-23T15:45:41.083@Veskah I didn't consider that possibility since I've never played the game with >1 deck but I can add the test case. – qdread – 2019-09-23T16:47:16.923