Skip to content

Instantly share code, notes, and snippets.

@gnyman
Created December 4, 2022 18:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gnyman/96d863559da87d3558b9cfbcaf9150b8 to your computer and use it in GitHub Desktop.
Save gnyman/96d863559da87d3558b9cfbcaf9150b8 to your computer and use it in GitHub Desktop.
# Open the input file and read the lines
with open("input.txt") as file:
lines = file.read().strip().split("\n")
# Initialize the counter for fully contained ranges
counter = 0
# Loop over the lines in the input file
for line in lines:
# Split the line into two parts by the comma
parts = line.split(",")
# Parse the first and second ranges
a = [int(x) for x in parts[0].split("-")]
b = [int(x) for x in parts[1].split("-")]
# Check if one range fully contains the other
if a[0] <= b[0] and b[1] <= a[1]:
counter += 1
elif b[0] <= a[0] and a[1] <= b[1]:
counter += 1
# Print the result
print(counter)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment