Skip to content

Instantly share code, notes, and snippets.

@itsdebartha
Last active April 16, 2022 06:34
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/ae3d43b8dc2f8090b82659787627141f to your computer and use it in GitHub Desktop.
Save itsdebartha/ae3d43b8dc2f8090b82659787627141f to your computer and use it in GitHub Desktop.
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