Created
November 19, 2019 02:55
-
-
Save alandipert/b02ccb83740617b7be4ca7dbcfc8e59c to your computer and use it in GitHub Desktop.
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
ops <- list('+' = `+`, '-' = `-`, '*' = `*`, '/' = `/`) | |
eval_expr <- function(f1, f2, f3) { | |
f2(f1(2, .5), f3(1.5, 4)) == -6.25 | |
} | |
find <- function() { | |
m <- gtools::permutations(4, 3, 1:4) | |
for (r in 1:nrow(m)) { | |
if (do.call(eval_expr, setNames(ops[m[r,]], NULL))) { | |
return(names(ops)[m[r,]]) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment