I want to store all feasible permutations for a target vector of size 24, that consists of (0,1).
For memory efficiency I use the below:
Test = data.table(permutations(n = 2,r = 12,v = c("zero","one"),repeats.allowed = T))
Test[, names(Test) := lapply(.SD, function(x) gsub("zero", "0,0", x))]
Test[, names(Test) := lapply(.SD, function(x) gsub("one", "1,1", x))]
Final output should adhere the following:
- Minimum number of consecutive 1's is 8 and maximum is 15 in the middle of the vector.
- At the start/end only consecutive 1's are permitted to be less than 8
- two 0's between consecutive 1's
Examples:
c(1,1,1,1,0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0,1,1,1,1)
- Correct
c(1,1,1,1,0,0,1,1,1,1,1,1,1,1,1,1,0,0,1,1,1,1,1,1)
- Correct
c(1,1,1,1,0,0,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0)
- Correct
c(0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0)
- Correct
c(0,0,1,1,0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0,1,1,1,1)
- Wrong: only 2 consecutive 1's
c(0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,1,1,0,1,1)
- Wrong: only one 0 between consecutive 1's at the end of the vector