Update all new Tasks
This commit is contained in:
parent
00a190b0a6
commit
91df62d461
5697 changed files with 93386 additions and 804 deletions
21
Task/ABC-Problem/R/abc-problem-2.r
Normal file
21
Task/ABC-Problem/R/abc-problem-2.r
Normal 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"))
|
||||
Loading…
Add table
Add a link
Reference in a new issue