How do you repeat sampling from a vector of characters until a certain sequence appears?

Viewed 71

There are 10 cards written as "S", "T", "A", "T", "I", "S", "T", "I", "C", "S". After picking ONE card randomly, you put the card back to the original place and mix it. Repeat this until "S","A","T" come out in order.

x<-c("S","T","A","T","I","S","T","I","C","S")
repeat{
  print(sample(x,1,replace=TRUE))}

I don't know how to stop when "S","A","T" comes out.

4 Answers
Related