一个函数将1~100按照提供的数组进行区间划分,如:[5,3,9],划分
的结果是1 ~ 3,4 ~ 5,6 ~ 9,10 ~ 100
def partition_numbers(ranges):
numbers = list(range(1, 101)) # 生成1到100的列表
partitions = []
start = 1
for size in ranges:
end = start + size - 1
partitions.append((start, end))
start = end + 1
if end < 100:
partitions.append((end + 1, 100))
return partitions
# 示例
ranges = [5, 3, 9]
result = partition_numbers(ranges)
print(result)