## Copyright (C) 2017 Dominic Walden
## This program is free software: you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation, either version 3 of the License, or
## (at your option) any later version.
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
## You should have received a copy of the GNU General Public License
## along with this program. If not, see .
unionRecursive <- function (thelist) {
if(length(thelist) == 1) {
thelist[[1]]
} else {
union(thelist[[1]],
unionRecursive(thelist[-1]))
}
}
checkComb <- function(comb, p) {
output <- list()
for(pirates in data.frame(combn(comb, p))) {
output[[(length(output)+1)]] <- unionRecursive(pirates)
}
output
}
checkCombLength <- function(comb, P, p) {
T <- length(data.frame(combn(P, p - 1)))
output <- TRUE
# Every p - 1 combinations of pirates should not have T total keys
for(vect in checkComb(comb, p - 1)) {
if(length(vect) == T) {
output <- FALSE
}
}
# Every p combinations of pirates should have T total keys
for(vect in checkComb(comb, p)) {
if(length(vect) != T) {
output <- FALSE
}
}
output
}