Write code in Scratch: Overlay between two intervals A1 = 62 A2 = 22 B1 = 4 B2 = 91…
- User
Write code in Scratch: Overlay between two intervals
A1 = 62 A2 = 22 B1 = 4 B2 = 91 Result: false (There's issue, overlayed would say "true)
- Assistant
To determine if there is an overlap between two intervals [A1, A2] and [B1, B2], you can use the following logic: Two intervals overlap if one starts before the other ends, and ends after the other starts.
Let's find the correct overlap logic and then write it in Scratch.
The correct logic for overlap:
- A1 <= B2
- A2 >= B1
In Scratch:
- Open Scratch and create a new project.