Skip to content

Instantly share code, notes, and snippets.

@itsdebartha
Last active May 10, 2022 17:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save itsdebartha/ea03eb51634dc3b472f23e9e2e7b29b9 to your computer and use it in GitHub Desktop.
Save itsdebartha/ea03eb51634dc3b472f23e9e2e7b29b9 to your computer and use it in GitHub Desktop.
rolls<-function(n) #function
{
j=0 #set the counter for subsequence to 0
x<-sample(1:6,n,replace=T) #roll n times
y<-which(x==1) #see which rolls are 1
for(i in y) #for every such rolls
{
if(n-i<5) break #if the index goes out of bounds, break
else if((x[i+1]==2)&&(x[i+2]==3)&&(x[i+3]==4)&&(x[i+4]==5)&&(x[i+5]==6))
#else check if the subsequence is 23456 or not
{
j=1 #if it is 23456, set j as 1
break #and break from the loop
}
}
return(j) #return the value of j
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment