Closed. This question needs
Update 1
A little update. To be fully compatible with your task, I have slightly improved the Deal_to_the_first_pair
function so that it takes a shuffled deck of cards as an argument and returns the number of cards until the first pair occurs.
Deal_to_the_first_pair2 = function(deck){
deck_card = str_split_fixed(deck, " ", 2)[,1]
i=2
while(length(unique(deck_card[1:i]))==length(deck_card[1:i])) i=i 1
i
}
set.seed(1111)
df2 = tibble(i = 1:ndealings) %>%
mutate(deck = map(i, ~sampleDeck())) %>%
mutate(ncards_dealt = map(deck, ~Deal_to_the_first_pair2(.x))) %>%
unnest(ncards_dealt)
df2
output
i deck ncards_dealt
<int> <list> <dbl>
1 1 <chr [52]> 7
2 2 <chr [52]> 8
3 3 <chr [52]> 5
4 4 <chr [52]> 9
5 5 <chr [52]> 5
6 6 <chr [52]> 8
7 7 <chr [52]> 5
8 8 <chr [52]> 5
9 9 <chr [52]> 3
10 10 <chr [52]> 2
Now you have it just like in your homework :-).