Skip to content

Instantly share code, notes, and snippets.

@tony91782
Created May 31, 2011 04:45
Show Gist options
  • Save tony91782/999874 to your computer and use it in GitHub Desktop.
Save tony91782/999874 to your computer and use it in GitHub Desktop.
trick_works = function(num_times=1, num_decks=1){
deck = rep(1:13, each=4,times =num_decks)
facedeck = pmin(deck, 10)
init= 1:10
secretnum = init
stop = length(deck)*num_times
mycards = sample(facedeck, replace=FALSE) ## Shuffle the Deck
data = init
draws = 1:stop
for(i in draws){
idx = i %% length(deck)
idx = ifelse(idx==0, 52, idx)
secretnum = secretnum -1
secretnum = ifelse(secretnum==0, mycards[idx],secretnum)
data=cbind(data, secretnum)
}
prob_works = sum(unname((table(secretnum)/10)^2))
return(prob_works)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment