5 kyu

Finding the Closest Maximum Values of a Function to an Upper Limit

86 of 212raulbc777

Description:

We have the following function of two variables x, y (values of x, y are in determined ranges of values):

The function above is studied for x, y, positive integers, and x ≠ y.

⌊ ⌋ - represents the function floor and | | the absolute value.

In the image below there is 3D graph that may show some features of the function:

xmin = 0, xmax = 10 ; ymin = 0, ymax = 10 and zmax (the same value of hMax) near 250.

The function has extremely high values for wider ranges of x and y.

We need a function max_val_f(), that accepts four arguments:

(1) range1: m ≤ x ≤ n -----> [m, n] (The values of x belong to the interval range1)

(2) range2: p ≤ y ≤ q -----> [p, q] (The values of y belong to the interval range2)

(3) hMax: f(x, y) ≤ hMax (The values of f(x, y) selected should be bellow or equal hMax)

(4) the length for the wanted array for the output

The function should output the largest values of f(x, y) less or equal than hMax, in increasing order (the amount of highest values coincides with the entry (4))

To explain graphicaly the features of our asked function:

max_val_f([m, n], [p, q], hMax, k) -------> [f(x1, y1), f(x2, y2), ....f(xk, yk)] # 

f(x1, y1) < f(x2, y2) < ....< f(xk, yk) ≤ hMax 

Let's see some cases:

range1 = [1, 10]
range2 = [1, 10]
hMax = 500
k = 4
max_val_f(range1, range2, hMax, k) -----> [81.0, 125.0, 243.0, 256.0]

range1 = [1, 50]
range2 = [1, 50]
hMax = 500
k = 4
max_val_f(range1, range2, hMax, k) -----> [361.0, 400.0, 441.0, 484.0]

range1 = [1, 50]
range2 = [1, 50]
hMax = 1000
k = 5
max_val_f(range1, range2, hMax, k) -----> [784.0, 841.0, 900.0, 961.0, 1000.0]
range1 = [1, 10]
range2 = [1, 10]
hMax = 500
k = 4
max_val_f(range1, range2, hMax, k) -----> [81.0, 125.0, 243.0, 256.0]

range1 = [1, 50]
range2 = [1, 50]
hMax = 500
k = 4
max_val_f(range1, range2, hMax, k) -----> [361.0, 400.0, 441.0, 484.0]

range1 = [1, 50]
range2 = [1, 50]
hMax = 1000
k = 5
max_val_f(range1, range2, hMax, k) -----> [784.0, 841.0, 900.0, 961.0, 1000.0]
range1 = (1, 10)
range2 = (1, 10)
hMax = 500
k = 4
maxValF range1 range2 hMax k -----> [81.0, 125.0, 243.0, 256.0]

range1 = (1, 50)
range2 = (1, 50)
hMax = 500
k = 4
maxValF range1 range2 hMax k -----> [361.0, 400.0, 441.0, 484.0]

range1 = (1, 50)
range2 = (1, 50)
hMax = 1000
k = 5
maxValF range1 range2 hMax k -----> [784.0, 841.0, 900.0, 961.0, 1000.0]
range1 = [1, 10]
range2 = [1, 10]
hMax = 500
k = 4
max_val_f(range1, range2, hMax, k) -----> [81.0, 125.0, 243.0, 256.0]

range1 = [1, 50]
range2 = [1, 50]
hMax = 500
k = 4
max_val_f(range1, range2, hMax, k) -----> [361.0, 400.0, 441.0, 484.0]

range1 = [1, 50]
range2 = [1, 50]
hMax = 1000
k = 5
max_val_f(range1, range2, hMax, k) -----> [784.0, 841.0, 900.0, 961.0, 1000.0]

Enjoy it and happy coding!

Fundamentals
Mathematics

Stats:

CreatedSep 27, 2015
PublishedSep 29, 2015
Warriors Trained1157
Total Skips393
Total Code Submissions893
Total Times Completed212
Python Completions86
Ruby Completions19
Haskell Completions16
JavaScript Completions35
CoffeeScript Completions4
Clojure Completions20
Java Completions39
C# Completions30
Total Stars18
% of votes with a positive feedback rating87% of 47
Total "Very Satisfied" Votes36
Total "Somewhat Satisfied" Votes10
Total "Not Satisfied" Votes1
Total Rank Assessments5
Average Assessed Rank
5 kyu
Highest Assessed Rank
4 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • raulbc777 Avatar
  • g964 Avatar
  • Voile Avatar
  • hobovsky Avatar
  • Just4FunCoder Avatar
  • saudiGuy Avatar
Ad