Beta

Linear functions intersection

Description:

This kata would about function intersections

Function – dependence of one variable on another.

This dependence can be expressed in the coordinate system in the form of a graph, and the graphs of two different linear functions can intersect at no more then one point.

Linear functions are functions of the form: y = mx + b.

Two functions, y1 and y2, intersect one another when, for a specific x, y1(x) = y2(x).

Your task in this kata is to determine whether if two functions intersect with another in a given interval (exclusive). The functions also may not intersect with one another.

For example, given y1 = x - 3, y2 = -x + 3, and the interval (-2,6):

y1 and y2 intersect at the point (3,0) and this intersection lies in the interval (-2 < 3 < 6) so return True in any other case return False.

Graphically (shown for illustration purposes only):

 5           \   ↑ y         :
 4           : \ |           : /
 3           :   ⍀           /
 2           :   | \       / :
 1           :   |   \   /   :
 0 ——————————:———+—————*—————:——→
-1           :   |   /   \   :  x
-2           :   | /       \ :
-3           :   ⌿           \ 
-4           : / |           : \ y=-x+
  -7-6-5-4-3-2-1 0 1 2 3 4 5 6 7

'/' - graph of y=x-3, '\' - graph of y=-x+3
'*' - intersection point,
':' - interval boundaries (-2<x<6)
  • Intervals are always valid.
  • Generation of random tests also allows the absence of some terms of the equation, defining the function, what can make it constant function too.

Enjoy /ᐠ。.。ᐟ\

Mathematics
Algorithms

More By Author:

Check out these other kata created by user902000

Stats:

CreatedMar 3, 2023
PublishedMar 4, 2023
Warriors Trained50
Total Skips2
Total Code Submissions163
Total Times Completed23
Python Completions23
Total Stars1
% of votes with a positive feedback rating77% of 13
Total "Very Satisfied" Votes7
Total "Somewhat Satisfied" Votes6
Total "Not Satisfied" Votes0
Total Rank Assessments15
Average Assessed Rank
6 kyu
Highest Assessed Rank
5 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • user902000 Avatar
Ad