Add count.py
This commit is contained in:
commit
2f658420eb
24
count.py
Normal file
24
count.py
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
# Mục đích là tìm dãy số thiếu trong dải number trong files numbers.txt
|
||||||
|
# file name: find_missing_numbers.py
|
||||||
|
|
||||||
|
def find_missing_numbers(filename, start=1, end=4384):
|
||||||
|
# Read all numbers from file
|
||||||
|
with open(filename, "r") as f:
|
||||||
|
numbers = set()
|
||||||
|
for line in f:
|
||||||
|
line = line.strip()
|
||||||
|
if line.isdigit(): # ensure it's a number
|
||||||
|
numbers.add(int(line))
|
||||||
|
|
||||||
|
# Generate full valid range
|
||||||
|
full_range = set(range(start, end + 1))
|
||||||
|
|
||||||
|
# Find what is missing
|
||||||
|
missing = sorted(full_range - numbers)
|
||||||
|
|
||||||
|
return missing
|
||||||
|
|
||||||
|
|
||||||
|
# Example usage:
|
||||||
|
missing_numbers = find_missing_numbers("numbers.txt")
|
||||||
|
print("Missing numbers:", missing_numbers)
|
||||||
Loading…
x
Reference in New Issue
Block a user