Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions