0

I try to convert the @JonathanAllan's Python code to R code. My attempt is below:

library(e1071) # permutations

n <- 24
sideSum <- 42

iterSolutions <- function(sideSum, n){

Q = c(list(seq(1, n)))
for(A in combn(seq(1, n), 4))
{
  if (sum(A) != sideSum) { next }
  Q1 = setdiff(Q, A)
# for a, d, b, c in list(permutations(A))[::2]:
  tmp = permutations(A)
  for ( c(a, d, b, c) in tmp[seq(1, length(tmp), by=2)]){
    for (B in combn(Q1, 3)){
         if (a + sum(B) != sideSum) { next }
         Q2 = setdiff(Q1, B)
    } # for B
    } # for a, b, d, c
} # for A
#......
return c(a, b, d, c)

} # function

Question. How to re-write the for-loop for a, d, b, c in list(permutations(A))[::2]: in R?

Nick
  • 1,086
  • 7
  • 21

0 Answers0