Question: Another example is: MaxProcChain (-3, [Proc.new{|x| x+1}, Proc.new{|x| x-3}, Proc.new{|x| x*-5}]) == 31, calculated as (((-3-3)*-5)+1) My code uses an array to skip any operations
![Another example is: MaxProcChain (-3, [Proc.new{|x| x+1}, Proc.new{|x| x-3}, Proc.new{|x| x*-5}])](https://s3.amazonaws.com/si.experts.images/answers/2024/09/66de68a46534a_81166de68a3e2746.jpg)
Another example is:
MaxProcChain (-3, [Proc.new{|x| x+1}, Proc.new{|x| x-3}, Proc.new{|x| x*-5}]) == 31, calculated as (((-3-3)*-5)+1)
My code uses an array to skip any operations that decreases the value, but it doesn't take into account negatives multiplied by other negatives, or larger negatives multiplied by negatives. I'm pretty sure I should be using recursion, but no amount of logical thinking allowing me to get an answer
- Description: Takes a list of procs and decides to either apply each proc or not to maximize the final or not. For example, if I have a list of procs: and an initial value x, then I take the maximum value of X You may assume each proc has type Integer Integer - Type: - Examples: MaxProcChain(2, [ Proc. new{xx+6}])=8 MaxProcChain(2, [ Proc. new{xx+4}, Proc. new{xx4]})=24 MaxProcchain (4,[ Proc. new{xx4},Procnew{xx+3}])=1
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
