Skip to content

Instantly share code, notes, and snippets.

@alandipert
Created November 19, 2019 02:55
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 alandipert/b02ccb83740617b7be4ca7dbcfc8e59c to your computer and use it in GitHub Desktop.
Save alandipert/b02ccb83740617b7be4ca7dbcfc8e59c to your computer and use it in GitHub Desktop.
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