Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
117 changes: 55 additions & 62 deletions README.md
Original file line number Diff line number Diff line change
@@ -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 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`

Program description:
**Output**: returns the winner (Player 1 or Player 2), 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: Player 1: `2H 7H 3H 5H JH`; Player 2: `2C 3H 4S 8C KH`
- Output: Player 1 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: 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: Player 1: `2H 2D 2S 5C 9D`; Player 2: `2C 3H 4S 8C KH`
- Output: Player 1 wins - three of a kind: 2

Pair
- 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 3D 5S KC KD White: 2C 3H 4S 8C KH
Output: Black wins - pair: King
- Input: Player 1: `2H 2D 2S 5C 9D`; Player 2: `2C 3H 8S 8C 8H`
- Output: Player 2 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: Player 1: `2H 3D 5S KC KD`; Player 2: `2C 3H 4S 8C KH`
- Output: Player 1 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: Player 1: `KS KD 5S 7C 8D`; Player 2: `2C 3H 4S KC KH`
- Output: Player 1 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: 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
Output: Tie
- Input: Player 1: `2H 3D 5S 9C KD`; Player 2: 2D `3H 5C 9S KH`
- Output: Tie
2 changes: 1 addition & 1 deletion config/config.exs
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 1 addition & 3 deletions lib/elixir_poker.ex
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
defmodule ElixirPoker do

def compare(player_1, player_2) do
def compare(player1_hand, player2_hand) do
""
end

end