Last active
September 2, 2020 14:29
-
-
Save tim-salabim/1354991e4b8fa6c61085121e54371a1a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
combiner = function(x, y = x) { | |
out = vector("list"); n = 1 | |
for (i in x) { | |
for (j in y) { | |
# if (i %in% j) { | |
# next | |
# } | |
out[[n]] = c(i, j) | |
n = n + 1 | |
} | |
} | |
return(out) | |
} | |
wrapper = function(x = list(c(0, 255), c(0, 255)), n = length(x)) { | |
for (h in (n - 1):1) { | |
out = if (h == n - 1) { | |
combiner(x[[h]], x[[h + 1]]) | |
} else { | |
combiner(x[[h]], out) | |
} | |
} | |
return(out) | |
} | |
combineArrs = function(x, y) { | |
out = vector("list", length(x)) | |
for (i in 1:length(x)) { | |
out[[i]] = c(x[i], y[i]) | |
} | |
return(out) | |
} | |
a = 1:3 | |
b = 10:12 | |
wrapper(combineArrs(a, b)) | |
[[1]] | |
[1] 1 2 3 | |
[[2]] | |
[1] 1 2 12 | |
[[3]] | |
[1] 1 11 3 | |
[[4]] | |
[1] 1 11 12 | |
[[5]] | |
[1] 10 2 3 | |
[[6]] | |
[1] 10 2 12 | |
[[7]] | |
[1] 10 11 3 | |
[[8]] | |
[1] 10 11 12 | |
## Thanks to Flo Detsch!! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To get rid of
eval
and include allMath
functions: