7 kyu

Quadrants 2: Segments

217 of 892EntityPlantt

Description:

Task

Your task is to check whether a segment is completely in one quadrant or it crosses more. Return true if the segment lies in two or more quadrants. If the segment lies within only one quadrant, return false.

There are two parameters: A (coord) and B (coord), the endpoints defining the segment AB.

No coordinate will be zero; expect that all X and Y are positive or negative.

Examples

  1. This whole segment is in the first quadrant.
    [(1, 2), (3, 4)] -> false
    
    Example 1
  2. This segment intersects the Y axis, therefore being in two quadrants: I and II.
    [(9, 3), (-1, 6)] -> true
    
    Example 2
  3. This segment is completely in the second quadrant.
    [(-1, 6), (-9, 1)] -> false
    
    Example 3

Predefined

There is a class named coord/Coord (see in code). It has the following members:

  • (constructor): Constructs the coordinate
    • x (number): The X coordinate
    • y (number): The Y coordinate
  • x (number): The X coordinate
  • y (number): The Y coordinate
  • operator== (bool): Compares two coordinates if they're the same
  • str (string): Turns coordinate into string

Task Series

  1. Quadrants
  2. Quadrants 2: Segments (this kata)
Fundamentals
Mathematics
Geometry

More By Author:

Check out these other kata created by EntityPlantt

Stats:

CreatedApr 18, 2023
PublishedApr 19, 2023
Warriors Trained1903
Total Skips33
Total Code Submissions2462
Total Times Completed892
C++ Completions217
JavaScript Completions230
TypeScript Completions50
Python Completions382
C Completions94
Total Stars21
% of votes with a positive feedback rating89% of 150
Total "Very Satisfied" Votes123
Total "Somewhat Satisfied" Votes22
Total "Not Satisfied" Votes5
Total Rank Assessments25
Average Assessed Rank
7 kyu
Highest Assessed Rank
6 kyu
Lowest Assessed Rank
8 kyu
Ad
Contributors
  • EntityPlantt Avatar
  • rowcased Avatar
  • mauro-1 Avatar
  • dfhwze Avatar
Ad