-
-
Save itsdebartha/90353161ef91e07bbe5787a8c837285b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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