-
-
Save itsdebartha/ae3d43b8dc2f8090b82659787627141f 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 | |
{ | |
j=0 #counter to check if the current roll is 6 | |
x<-sample(1:6,1) #roll once | |
i=1 #increase the counter | |
if(x==6) #if the roll is a six | |
{ | |
j=1 #set this counter to 1 | |
x<-sample(1:6,1) #roll again | |
i=i+1 #increase the counter | |
if(x!=6) j=0 #if the roll is not 6, set j back to 0 | |
} | |
while(j!=1) #while j is 0 | |
{ | |
x<-sample(1:6,1) #roll once | |
i=i+1 #increase the roll counter | |
if(x==6) #if the roll is a six | |
{ | |
j=1 #set this counter to 1 | |
x<-sample(1:6,1) #roll again | |
i=i+1 #increase the counter | |
if(x!=6) j=0 #if the roll is not 6, set j back to 0 | |
} | |
} | |
return(i) #return the roll counter | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment