From 339d55d5161821a03fd1330328f574613f1f0751 Mon Sep 17 00:00:00 2001 From: Everett Griffiths Date: Mon, 20 Feb 2023 09:09:36 -0500 Subject: [PATCH 1/4] Clarifies wording, improves formatting for easier readability --- README.md | 117 +++++++++++++++++++++++++----------------------------- 1 file changed, 55 insertions(+), 62 deletions(-) diff --git a/README.md b/README.md index 2bfd9f7..9d804b6 100644 --- a/README.md +++ b/README.md @@ -1,96 +1,89 @@ # ElixirPoker -**TODO: Add description** +This repo describes an Elixir coding challenge where the interviewee is tasked with implementing part of a Poker game. -POKER INTERVIEW QUESTION +## Program Requirements +Build a function which can determine the winner of a hand of poker between two players (designated as white and black). A hand has 5 cards. +**Input**: accepts two strings representing a hand of cards, e.g. `2C 3H 4S 8C KH` and `QH QD 5S 7C 8D` -Program description: +**Output**: returns the winner (white or black), and optionally returns the reason for winning. -Build a program which can determine the winner of a poker game, looking at players hands only. A hand has 5 cards. - -Input => takes two string of characters representing the cards for each player (e.g. "2C 3H 4S 8C KH" and "QH QD 5S 7C 8D") -Output => returns the winner (optional: returns the reason for winning) - - - -Game description: +## Game description - A poker deck contains 52 cards. -- Each of the two players get 5. -- Each card has a suit which is one of CLUBS, DIAMONDS, HEARTS, or SPADES (denoted C, D, H, and S in the input data). -- Each card also has a value which is one of 2, 3, 4, 5, 6, 7, 8, 9, 10, jack, queen, king, ace (denoted 2, 3, 4, 5, 6, 7, 8, 9, T, J, Q, K, A). +- Each of the two players gets a hand of 5 cards. +- Each card has a suit which is one of CLUBS, DIAMONDS, HEARTS, or SPADES (denoted C, D, H, and S in the input data). +- Each card has a value which is one of 2, 3, 4, 5, 6, 7, 8, 9, 10, jack, queen, king, ace (denoted 2, 3, 4, 5, 6, 7, 8, 9, T, J, Q, K, A). - Suits are not ranked (they are equal in term of scoring) - Values are ranked as presented above (2 lowest and Ace highest) Normal poker combinations (by rank): -Straight flush: 9C 8C 7C 6C 5C (5 consecutive & 5x same suit) -Four of a kind: 8D 8C 8S 8H 5C (4x value) -Full House: AC AD AH 8S 8C (3x value + 2x value) -Flush: AS 9S 7S 6S 3S (5x suit) -Straight: 9H 8D 7S 6C 5H (5 consecutive) -Three of a Kind: AC AD AH 9H 3S (3x) -Two Pairs: JC JD 9H 9S 7S (2x value + 2x value) -Pair: JC JD 10H 9S 7S (2x value) -High Card: AC 9S 7C 8S 3D +| Hand | Example | Description | +|----------------------|---------------------|--------------------------------| +| Straight flush | `9C 8C 7C 6C 5C` | 5 consecutive of the same suit | +| Four of a kind | `8D 8C 8S 8H 5C` | 4x value | +| Full House | `AC AD AH 8S 8C` | 3x value + 2x value | +| Flush | `AS 9S 7S 6S 3S` | 5x same suit | +| Straight | `9H 8D 7S 6C 5H` | 5 consecutive | +| Three of a Kind | `AC AD AH 9H 3S` | 3x | +| Two Pairs | `JC JD 9H 9S 7S` | 2x value + 2x value | +| Pair | `JC JD 10H 9S 7S` | 2x value | +| High Card | `AC 9S 7C 8S 3D` | | Poker combinations for this interview (by rank): -Flush: AS 9S 7S 6S 3S (5x suit) -Three of a Kind: AC AD AH 9H 3S (3x) -Pair: JC JD 10H 9S 7S (2x value) -High Card: AC 9S 7C 8S 3D - - -Examples: - -Flush: - -Input: Black: 2H 7H 3H 5H JH White: 2C 3H 4S 8C KH -Output: Black wins - flush: J - -Input: Black: 2H 7H 3H 5H JH White: 2C 3C 4C 8C KC -Output: White wins - flush: K - +| Hand | Example | Description | +|----------------------|---------------------|---------------| +| Flush | `AS 9S 7S 6S 3S` | 5x same suit | +| Three of a Kind | `AC AD AH 9H 3S` | 3x | +| Pair | `JC JD 10H 9S 7S` | 2x value | +| High Card | `AC 9S 7C 8S 3D` | | -Three of a Kind +## Examples -Input: Black: 2H 2D 2S 5C 9D White: 2C 3H 4S 8C KH -Output: Black wins - three of a kind: 2 +### Flush -Input: Black: 2H 2D 2S 5C 9D White: 2C 3H 4S 8C 8H -Output: Black wins - three of a kind: 2 +- Input: Black: `2H 7H 3H 5H JH`; White: `2C 3H 4S 8C KH` +- Output: Black wins - flush: J -Input: Black: 2H 2D 2S 5C 9D White: 2C 3H 8S 8C 8H -Output: White wins - three of a kind: 8 +- Input: Black: `2H 7H 3H 5H JH`; White: `2C 3C 4C 8C KC` +- Output: White wins - flush: K +### Three of a Kind +- Input: Black: `2H 2D 2S 5C 9D`; White: `2C 3H 4S 8C KH` +- Output: Black wins - three of a kind: 2 -Pair +- Input: Black: `2H 2D 2S 5C 9D`; White: `2C 3H 4S 8C 8H` +- Output: Black wins - three of a kind: 2 -Input: Black: 2H 3D 5S KC KD White: 2C 3H 4S 8C KH -Output: Black wins - pair: King +- Input: Black: `2H 2D 2S 5C 9D`; White: `2C 3H 8S 8C 8H` +- Output: White wins - three of a kind: 8 -Input: Black: QH QD 5S 7C 8D White: 2C 3H 4S KC KH -Output: White wins - pair: King +### Pair -Input: Black: KS KD 5S 7C 8D White: 2C 3H 4S KC KH -Output: Black wins - High: 8 +- Input: Black: `2H 3D 5S KC KD`; White: `2C 3H 4S 8C KH` +- Output: Black wins - pair: King +- Input: Black: `QH QD 5S 7C 8D`; White: `2C 3H 4S KC KH` +- Output: White wins - pair: King +- Input: Black: `KS KD 5S 7C 8D`; White: `2C 3H 4S KC KH` +- Output: Black wins - High: 8 -High Cards +### High Cards -Input: Black: 2H 3D 5S 9C KD White: 2C 3H 4S 8C AH -Output: White wins - high card: Ace +- Input: Black: `2H 3D 5S 9C KD`; White: `2C 3H 4S 8C AH` +- Output: White wins - high card: Ace -Input: Black: 2H 3D 5S 9C AD White: 2C 3H 4S 8C AH -Output: Black wins - high card: 9 +- Input: Black: `2H 3D 5S 9C AD`; White: `2C 3H 4S 8C AH` +- Output: Black wins - high card: 9 -Input: Black: 2H 3D 5S 9C AD White: 9H 3H 4S 8C AH -Output: White wins - high card: 8 +- Input: Black: `2H 3D 5S 9C AD`; White: `9H 3H 4S 8C AH` +- Output: White wins - high card: 8 -Input: Black: 2H 3D 5S 9C KD White: 2D 3H 5C 9S KH -Output: Tie +- Input: Black: `2H 3D 5S 9C KD`; White: 2D `3H 5C 9S KH` +- Output: Tie From be39888542c1eedf371d3c4a023b00d709bdd82d Mon Sep 17 00:00:00 2001 From: Everett Griffiths Date: Mon, 20 Feb 2023 09:10:14 -0500 Subject: [PATCH 2/4] Modifies example function input to be consistent with instructions (refs hands instead of players) --- lib/elixir_poker.ex | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/elixir_poker.ex b/lib/elixir_poker.ex index 062fa83..c95ca6f 100644 --- a/lib/elixir_poker.ex +++ b/lib/elixir_poker.ex @@ -1,7 +1,5 @@ defmodule ElixirPoker do - - def compare(player_1, player_2) do + def compare(white_hand, black_hand) do "" end - end From b176d02776a82f9981a992fa9d896b5bd939adec Mon Sep 17 00:00:00 2001 From: Everett Griffiths Date: Fri, 24 Feb 2023 13:56:39 -0500 Subject: [PATCH 3/4] Updates use Mix.Config to import Config --- config/config.exs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/config.exs b/config/config.exs index a3e73c0..45bad68 100644 --- a/config/config.exs +++ b/config/config.exs @@ -1,6 +1,6 @@ # This file is responsible for configuring your application # and its dependencies with the aid of the Mix.Config module. -use Mix.Config +import Config # This configuration is loaded before any dependency and is restricted # to this project. If another project depends on this project, this From 2617a920667ab25adf48c3cd8efc7061101b0482 Mon Sep 17 00:00:00 2001 From: Everett Griffiths Date: Fri, 24 Feb 2023 13:57:30 -0500 Subject: [PATCH 4/4] Changes refs to Black and White players to Player 1 and Player 2 to match verbiage used in tests --- README.md | 50 ++++++++++++++++++++++----------------------- lib/elixir_poker.ex | 2 +- 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index 9d804b6..a6ccc46 100644 --- a/README.md +++ b/README.md @@ -4,11 +4,11 @@ This repo describes an Elixir coding challenge where the interviewee is tasked w ## Program Requirements -Build a function which can determine the winner of a hand of poker between two players (designated as white and black). A hand has 5 cards. +Build a function which can determine the winner of a hand of poker between two players (designated as Player 1 and Player 2). A hand has 5 cards. **Input**: accepts two strings representing a hand of cards, e.g. `2C 3H 4S 8C KH` and `QH QD 5S 7C 8D` -**Output**: returns the winner (white or black), and optionally returns the reason for winning. +**Output**: returns the winner (Player 1 or Player 2), and optionally returns the reason for winning. ## Game description @@ -46,44 +46,44 @@ Poker combinations for this interview (by rank): ### Flush -- Input: Black: `2H 7H 3H 5H JH`; White: `2C 3H 4S 8C KH` -- Output: Black wins - flush: J +- Input: Player 1: `2H 7H 3H 5H JH`; Player 2: `2C 3H 4S 8C KH` +- Output: Player 1 wins - flush: J -- Input: Black: `2H 7H 3H 5H JH`; White: `2C 3C 4C 8C KC` -- Output: White wins - flush: K +- Input: Player 1: `2H 7H 3H 5H JH`; Player 2: `2C 3C 4C 8C KC` +- Output: Player 2 wins - flush: K ### Three of a Kind -- Input: Black: `2H 2D 2S 5C 9D`; White: `2C 3H 4S 8C KH` -- Output: Black wins - three of a kind: 2 +- Input: Player 1: `2H 2D 2S 5C 9D`; Player 2: `2C 3H 4S 8C KH` +- Output: Player 1 wins - three of a kind: 2 -- Input: Black: `2H 2D 2S 5C 9D`; White: `2C 3H 4S 8C 8H` -- Output: Black wins - three of a kind: 2 +- Input: Player 1: `2H 2D 2S 5C 9D`; Player 2: `2C 3H 4S 8C 8H` +- Output: Player 1 wins - three of a kind: 2 -- Input: Black: `2H 2D 2S 5C 9D`; White: `2C 3H 8S 8C 8H` -- Output: White wins - three of a kind: 8 +- Input: Player 1: `2H 2D 2S 5C 9D`; Player 2: `2C 3H 8S 8C 8H` +- Output: Player 2 wins - three of a kind: 8 ### Pair -- Input: Black: `2H 3D 5S KC KD`; White: `2C 3H 4S 8C KH` -- Output: Black wins - pair: King +- Input: Player 1: `2H 3D 5S KC KD`; Player 2: `2C 3H 4S 8C KH` +- Output: Player 1 wins - pair: King -- Input: Black: `QH QD 5S 7C 8D`; White: `2C 3H 4S KC KH` -- Output: White wins - pair: King +- Input: Player 1: `QH QD 5S 7C 8D`; Player 2: `2C 3H 4S KC KH` +- Output: Player 2 wins - pair: King -- Input: Black: `KS KD 5S 7C 8D`; White: `2C 3H 4S KC KH` -- Output: Black wins - High: 8 +- Input: Player 1: `KS KD 5S 7C 8D`; Player 2: `2C 3H 4S KC KH` +- Output: Player 1 wins - High: 8 ### High Cards -- Input: Black: `2H 3D 5S 9C KD`; White: `2C 3H 4S 8C AH` -- Output: White wins - high card: Ace +- Input: Player 1: `2H 3D 5S 9C KD`; Player 2: `2C 3H 4S 8C AH` +- Output: Player 2 wins - high card: Ace -- Input: Black: `2H 3D 5S 9C AD`; White: `2C 3H 4S 8C AH` -- Output: Black wins - high card: 9 +- Input: Player 1: `2H 3D 5S 9C AD`; Player 2: `2C 3H 4S 8C AH` +- Output: Player 1 wins - high card: 9 -- Input: Black: `2H 3D 5S 9C AD`; White: `9H 3H 4S 8C AH` -- Output: White wins - high card: 8 +- Input: Player 1: `2H 3D 5S 9C AD`; Player 2: `9H 3H 4S 8C AH` +- Output: Player 2 wins - high card: 8 -- Input: Black: `2H 3D 5S 9C KD`; White: 2D `3H 5C 9S KH` +- Input: Player 1: `2H 3D 5S 9C KD`; Player 2: 2D `3H 5C 9S KH` - Output: Tie diff --git a/lib/elixir_poker.ex b/lib/elixir_poker.ex index c95ca6f..ca72556 100644 --- a/lib/elixir_poker.ex +++ b/lib/elixir_poker.ex @@ -1,5 +1,5 @@ defmodule ElixirPoker do - def compare(white_hand, black_hand) do + def compare(player1_hand, player2_hand) do "" end end