This file contains hidden or 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
def getmax nums, ops, dbg=0, &f | |
# f is action performed on numbers before comparing (like taking absolute value) | |
maxn = nil | |
pat = nil | |
(0...ops.size).to_a.permutation do |p| # iterate over each possible pattern | |
begin | |
n = solve(nums, ops, p, dbg - 1) # attempt to solve (based on given pattern) | |
if n.infinite? | |
n = nil | |
raise ZeroDivisionError, "divided by 0" |