Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.