Skip to content

Instantly share code, notes, and snippets.

@adam-gruer
Created October 18, 2018 10:46
Show Gist options
  • Save adam-gruer/b23931233e658b4d66f3e0de1f6522e4 to your computer and use it in GitHub Desktop.
Save adam-gruer/b23931233e658b4d66f3e0de1f6522e4 to your computer and use it in GitHub Desktop.
setup <- function() {
face = c("king", "queen", "jack", "ten", "nine", "eight", "seven", "six",
"five", "four", "three", "two", "ace")
suit = c("spades","clubs","hearts","diamonds")
value = 13:1
DECK <- data.frame( face = rep(face, length(suit)) ,
suit = rep(suit, each = length(face)),
value = value)
DEAL <- function() {
card <- deck[1, ]
assign("deck", deck[-1, ], envir = parent.env(environment()))
card
}
SHUFFLE <- function(){
random <- sample(1:52, size = 52)
assign("deck", DECK[random, ], envir = parent.env(environment()))
}
list(deal = DEAL, shuffle = SHUFFLE)
}
cards <- setup()
shuffle <- cards$shuffle
deal <- cards$deal
shuffle()
deal()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment