Created
December 15, 2018 11:03
-
-
Save Sleepingwell/0ffbf1ca907f2174dc19ce113fab727d to your computer and use it in GitHub Desktop.
Datalab quiz workings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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