Created
October 18, 2018 10:46
-
-
Save adam-gruer/b23931233e658b4d66f3e0de1f6522e4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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