Skip to content

Instantly share code, notes, and snippets.

@itsdebartha
Last active April 17, 2022 12:58
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/90353161ef91e07bbe5787a8c837285b to your computer and use it in GitHub Desktop.
Save itsdebartha/90353161ef91e07bbe5787a8c837285b 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 difference is not 1
{
x<-y;y<-sample(1:6,1) #replace the second roll with the first one and roll again
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