-
-
Save itsdebartha/46f7ae9571d19fa707147e54256d72f7 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 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