Skip to content

Instantly share code, notes, and snippets.

@Sleepingwell
Created December 15, 2018 11:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Sleepingwell/0ffbf1ca907f2174dc19ce113fab727d to your computer and use it in GitHub Desktop.
Save Sleepingwell/0ffbf1ca907f2174dc19ce113fab727d to your computer and use it in GitHub Desktop.
Datalab quiz workings
install.packages('pracma')
mb <- rbind(
c(1,1,0,0),
c(0,0,1,1),
c(1,0,1,0),
c(0,1,0,1)
)
b <- c(24, 14, 26, 12, 12, 29, 11, 30, 12)
z <- matrix(0,4,4)
B <- rbind(
cbind(mb, z),
cbind(z, mb),
c(1,0,0,0,1,0,0,0)
)
colnames(B) <- paste(
rep('x', 8),
rep(c(0, 1), each=4),
rep(c(0, 1), each=2, times=2),
rep(c(0, 1), times=4), sep='')
rres <- pracma::rref(cbind(B, b))
rres <- rres[1:7,]
tester <- function(val) {
# I looked at rres to determine this next line
c(rres[,9] - val * rres[,8], val)
}
res <- sapply(1:max(b), tester)
res <- res[,apply(res, 2, function(x) all(x >= 0))]
print(res)
o.r <- function(n, e) {
for(a in 1:(n-1)) {
for(b in 1:15) {
res <- (a/(n-a))/(b/(16-b))
if(res > e-.1 && res < e+.1) {
cat(c(n, a, b, res), sep=', '); cat('\n')
}
}
}
}
o.r(35, 1.42)
o.r(27, 1.67)
o.r(6, 1.49)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment