Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 365237
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T13:31:04+00:00 2026-05-12T13:31:04+00:00

This is hopefully a very simple maths question. If I have two number ranges,

  • 0

This is hopefully a very simple maths question. If I have two number ranges, what is the simplest and most efficient way to check if they clash, eg:

10-20 and 11-14 // clash as B is contained in A
11-15 and 20-22 // don't clash
24-26 and 20-30 // clash as A is contained in B
15-25 and 20-30 // clash as they overlap at each end

I currently have this mess, but there must be a much simpler way to do this check:

$clash = ($b1 >= $a1 && $b1 <= $a2)
    || ($b2 >= $a1 && $b2 <= $a2)
    || ($a1 >= $b1 && $a1 <= $b2)
    || ($a2 >= $b1 && $a2 <= $b2);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T13:31:05+00:00Added an answer on May 12, 2026 at 1:31 pm

    Well, first make sure you have well-ordered pairs (probably a good idea anyway, depending on what you plan to do with them):

    if($a1 > $a2) {
        // swap $a1 and $a2
        $temp = $a1;
        $a1 = $a2;
        $a2 = $temp;
    }
    if($b1 > $b2) {
        // swap $b1 and $b2
        $temp = $b1;
        $b1 = $b2;
        $b2 = $temp;
    }
    

    Then you should be able to simplify to:

    $clash = ($a2 <= $b1) || ($a1 >= $b2);
    

    Edit: Whoops, got that test backwards! Try:

    $clash = !(($a2 <= $b1) || ($a1 >= $b2));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hopefully this is a very simple question. I have a makefile pattern rule that
This is a very simple, (hopefully) question. I am new to working with DateTime
This is hopefully a simple question: I have an OpenGL texture and would like
This is hopefully a very simple question, but one a lot of Googling has
This isn't a very simple question, but hopefully someone has run across it. I
Hopefully this is a very simple question. Following is the C pgm (test.c) I
Hopefully this is very simple. I have a central activity that can be launched
I don't understand MEF very well, so hopefully this is a simple fix of
This will hopefully be a simple one: I have a div I want to
Hopefully this is simple: I have a relatively long list where each list item

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.