-
-
Save gnyman/69699fc6fdc1460191ea2108596cf419 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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