new files

This commit is contained in:
Ingy döt Net 2013-04-10 12:38:42 -07:00
parent 3af7344581
commit 86c034bb8b
1364 changed files with 21352 additions and 0 deletions

View file

@ -0,0 +1,5 @@
balanced <- function(str){
str <- strsplit(str, "")[[1]]
str <- ifelse(str=='[', 1, -1)
all(cumsum(str) >= 0) && sum(str) == 0
}

View file

@ -0,0 +1,3 @@
balanced <- function(str) {
regexpr('^(\\[(?1)*\\])*$', str, perl=TRUE) > -1
}

View file

@ -0,0 +1,6 @@
rand.parens <- function(n) paste(permute(c(rep('[',n),rep(']',n))),collapse="")
as.data.frame(within(list(), {
parens <- replicate(10, rand.parens(sample.int(10,size=1)))
balanced <- sapply(parens, balanced)
}))

View file

@ -0,0 +1,11 @@
balanced parens
1 FALSE ][][
2 FALSE [][[]]][[]][]]][[[
3 FALSE ][[][][]][][[]
4 FALSE ][][][][][][][
5 TRUE [[[][]]][[[][][]]]
6 TRUE []
7 FALSE ]][[][[]
8 FALSE []]]][[[]][[[]
9 TRUE [[[[][[][]]]]]
10 TRUE []