Update all new Tasks

This commit is contained in:
Ingy döt Net 2015-02-20 09:02:09 -05:00
parent 00a190b0a6
commit 91df62d461
5697 changed files with 93386 additions and 804 deletions

View file

@ -0,0 +1,43 @@
blocks <- rbind(c("B","O"),
c("X","K"),
c("D","Q"),
c("C","P"),
c("N","A"),
c("G","T"),
c("R","E"),
c("T","G"),
c("Q","D"),
c("F","S"),
c("J","W"),
c("H","U"),
c("V","I"),
c("A","N"),
c("O","B"),
c("E","R"),
c("F","S"),
c("L","Y"),
c("P","C"),
c("Z","M"))
canMake <- function(x) {
x <- toupper(x)
used <- rep(FALSE, dim(blocks)[1L])
charList <- strsplit(x, character(0))
tryChars <- function(chars, pos, used, inUse=NA) {
if (pos > length(chars)) {
TRUE
} else {
used[inUse] <- TRUE
possible <- which(blocks == chars[pos] & !used, arr.ind=TRUE)[, 1L]
any(vapply(possible, function(possBlock) tryChars(chars, pos + 1, used, possBlock), logical(1)))
}
}
setNames(vapply(charList, tryChars, logical(1), 1L, used), x)
}
canMake(c("A",
"BARK",
"BOOK",
"TREAT",
"COMMON",
"SQUAD",
"CONFUSE"))

View file

@ -0,0 +1,21 @@
canMakeNoRecursion <- function(x) {
x <- toupper(x)
charList <- strsplit(x, character(0))
getCombos <- function(chars) {
charBlocks <- data.matrix(expand.grid(lapply(chars, function(char) which(blocks == char, arr.ind=TRUE)[, 1L])))
charBlocks <- charBlocks[!apply(charBlocks, 1, function(row) any(duplicated(row))), , drop=FALSE]
if (dim(charBlocks)[1L] > 0L) {
t(apply(charBlocks, 1, function(row) apply(blocks[row, , drop=FALSE], 1, paste, collapse="")))
} else {
character(0)
}
}
setNames(lapply(charList, getCombos), x)
}
canMakeNoRecursion(c("A",
"BARK",
"BOOK",
"TREAT",
"COMMON",
"SQUAD",
"CONFUSE"))