Skip to content

Instantly share code, notes, and snippets.

@itsdebartha
Last active April 18, 2022 14:32
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/46f7ae9571d19fa707147e54256d72f7 to your computer and use it in GitHub Desktop.
Save itsdebartha/46f7ae9571d19fa707147e54256d72f7 to your computer and use it in GitHub Desktop.
rolls<-function() #function
{
x<-sample(1:6,1);y<-sample(1:6,1) #roll twice
i=2 #set the roll counter
while(abs(x-y)>1) #while their absolute diff is more than 1
{
x<-y;y<-sample(1:6,1) #replace the second roll with the first one and roll
i=i+1 #increase the counter
}
return(i) #return no. of rolls
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment