Skip to content

Instantly share code, notes, and snippets.

@justyntemme
Created July 19, 2016 03:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save justyntemme/b0c27a905d71589d2c57aa3b9b4ad2f6 to your computer and use it in GitHub Desktop.
Save justyntemme/b0c27a905d71589d2c57aa3b9b4ad2f6 to your computer and use it in GitHub Desktop.
Coder Radio Challenge 1
package main
import (
"fmt"
"strings"
)
/*Explanation of solution
blackJackCS is a map with the key value being that of myhand on the blackjack cheat sheet, the val value is an array.
The dealers hand is represented by the position in the array, for example, dealer hand of 2 is represented by positin 2 in the array
the array is of length 11, and holds the suggested solution to the current hand set
With this solution only one call is preformed after user input, everything is mapped and ready
*/
func main() {
//vars
blackJackCS := map[string][]string{
//MyHand nswer to question, order in the array is dealers hand, A is represented with 11
"8": strings.Split("H.H.H.H.H.H.H.H.H.H", "."),
"9": strings.Split("H.D.D.D.D.H.H.H.H.H", "."),
"10": strings.Split("D.D.D.D.D.D.D.D.J.H", "."),
"11": strings.Split("D.D.D.D.D.D.D.D.D.D", "."),
"12": strings.Split("H.H.S.S.S.H.H.H.H.H", "."),
"13": strings.Split("S.S.S.S.S.H.H.H.H.H", "."),
"14": strings.Split("S.S.S.S.S.H.H.H.H.H", "."),
"15": strings.Split("S.S.S.S.S.H.H.H.X/H.X/H", "."),
"16": strings.Split("S.S.S.S.S.H.H.X/H.X/H.X/H", "."),
"17": strings.Split("S.S.S.S.S.S.S.S.S.X/S", "."),
"A,2": strings.Split("H.H.H.D.D.H.H.H.H.H", "."),
"A,3": strings.Split("H.H.H.D.D.H.H.H.H.H", "."),
"A,4": strings.Split("H.H.D.D.D.H.H.H.H.H", "."),
"A,5": strings.Split("H.H.D.D.D.H.H.H.H.H", "."),
"A,6": strings.Split("H.D.D.D.D.H.H.H.H.H", "."),
"A,7": strings.Split("S.DS.DS.DS.DS.S.S.H.H.H", "."),
"A,8": strings.Split("S.S.S.S.S.S.S.S.S.S", "."),
"A,9": strings.Split("S.S.S.S.S.S.S.S.S.S", "."),
"2,2": strings.Split("SP.SP.SP.SP.SP.SP.H.H.H.H", "."),
"3,3": strings.Split("SP.SP.SP.SP.SP.SP.H.H.H.H", "."),
"4,4": strings.Split("H.H.H.SP.SP.H.H.H.H.H", "."),
"5,5": strings.Split("D.D.D.D.D.D.D.D.D.H.H", "."),
"6,6": strings.Split("SP.SP.SP.SP.SP.H.H.H.H.H", "."),
"7,7": strings.Split("SP.SP.SP.SP.SP.SP.H.H.H.H", "."),
"8,8": strings.Split("SP.SP.SP.SP.SP.SP.SP.SP.SP.X/P", "."),
"9,9": strings.Split("SP.SP.SP.SP.SP.S.SP.SP.S.S", "."),
"10,10": strings.Split("S.S.S.S.S.S.S.S.S.S", "."),
"A,A": strings.Split("SP.SP.SP.SP.SP.SP.SP.SP.SP.SP", "."),
}
var dealerCards int
var cards string
var solution []string
var ok bool
//input
fmt.Println("Please enter your hand with the non-numbered card first, replacing King Queen and jack with the value in the following format, Card,Card.")
fmt.Println("Example: Ace and 4 would be 'A,4'")
fmt.Scan(&cards)
fmt.Println("Please enter Dealers hand Value using 11 as ace")
fmt.Scan(&dealerCards)
//Processing
solution, ok = blackJackCS[cards]
if ok == false {
fmt.Println("Error, invalid input format")
}
//output
switch solution[dealerCards-2] {
case "H":
fmt.Println("Hit")
case "S":
fmt.Println("Stand")
case "D":
fmt.Println("Double if allowed, otherwise Hit")
case "DS":
fmt.Println("Double if allowed otherwise Stand")
case "SP":
fmt.Println("Split")
case "X/H":
fmt.Println("Surrender if allowed, otherwise Hit")
case "X/P":
fmt.Println("Surrender if allowed otherwise Split")
case "X/S":
fmt.Println("Surrender if allowed otherwise Stand")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment