Created
December 13, 2017 22:49
-
-
Save adam-garcia/c566d8e85521c8ffb9b5780651fb67e8 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
#' santa(guests) is a function that assigns guests to a "secret santa" gift swap | |
#' @param guests the vector of partygoers | |
#' @return a tibble, with <guests> assigned in "to" and "from" columns | |
library(magrittr) | |
library(tibble) | |
santa <- function(guests) { | |
n <- length(guests) | |
tibble ( | |
from = guests %>% sample(n), | |
to = c(from[-1], from[1]) | |
) %>% | |
return() | |
} | |
santa(letters[1:10]) | |
#> # A tibble: 10 x 2 | |
#> from to | |
#> <chr> <chr> | |
#> 1 e h | |
#> 2 h b | |
#> 3 b d | |
#> 4 d a | |
#> 5 a g | |
#> 6 g c | |
#> 7 c i | |
#> 8 i j | |
#> 9 j f | |
#> 10 f e | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment