Skip to content

Instantly share code, notes, and snippets.

@gnyman
Created December 4, 2022 18:49
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/69699fc6fdc1460191ea2108596cf419 to your computer and use it in GitHub Desktop.
Save gnyman/69699fc6fdc1460191ea2108596cf419 to your computer and use it in GitHub Desktop.
import sys
# Check if the filename was provided as an argument
if len(sys.argv) < 2:
print("Please provide the input filename as an argument.")
sys.exit(1)
# Get the input filename from the command-line argument
filename = sys.argv[1]
# Open the input file and read the lines
with open(filename) as file:
lines = file.read().strip().split("\n")
# Initialize the counter for overlapping 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 the ranges overlap
if a[0] <= b[1] and b[0] <= a[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