Skip to content

Instantly share code, notes, and snippets.

@jaye-ross
Last active November 13, 2015 23:50
Show Gist options
  • Save jaye-ross/5e751a09ac32641904ec to your computer and use it in GitHub Desktop.
Save jaye-ross/5e751a09ac32641904ec to your computer and use it in GitHub Desktop.
Quanta Magazine Puzzle Formula Tester
f = function(expr){
x = c(13,26,2,4,6,3,9,12,8,10,5,15,18,14,7,21,24,16)
failure = FALSE
for(i in seq_along(x)){
result = eval(expr)
if(length(result) != 1) next
print(sprintf("%s, %s, %s",i,x[i],result))
if(result != x[i]){
failure = TRUE
break
}
}
message = ifelse(failure,"FAILED","PASSED")
print(message)
}
# test
f(expression(x[i-1] + x[i-2]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment