This question is a variation of this entry, but more complex in the way that the condition doesn't have to be met just once, but rather at every single step of the loop.
CONTEXT: I am trying to sample a vector:
balls = c(R = rep(1,2), G = rep(2,2), B = rep(3,2), W = rep(4,3), Y = 5, b = 6, O = 7)
in such a way that no color ("R", "G", "B", "W", "Y", "B", "O") with duplicate or triplicate number of balls (e.g. "R" or "W") ends up being aligned contiguously (no two balls of the same color side by side). This is meant to verify this post in MathSE.
So here is the pseudocode I would like to implement:
sam[1] = sample(balls, 1)
for (i in 2:length(balls)){
remaining = balls[- which(balls = sam[i])]
ifelse(x <- sample(remaining) != sam[i], sam[i + 1] = x, IFELSE ALL OVER AGAIN)
}