import Foundation
print("Xcode Swift")
// create some ranges
let Range1 = 1 ... 10
let Range2 = 14 ... 22
let Range3 = 26 ... 30
let Range4 = 40 ... 44
let Range5 = 50 ... 60
print("Range1 SUM:",Range1.count)
print("Range2 SUM:",Range2.count)
print("Range3 SUM:",Range3.count)
print("Range4 SUM:",Range4.count)
print("Range5 SUM:",Range5.count)
// Count the ranges together from Range2 to Range4
let RangeBetween =
Range2.count +
Range3.count +
Range4.count
// print the number of values
print("SUM: From Range2 to Range4:",RangeBetween)
//How to print number, which missing between ranges?
I should find the missing numbers between the series, how is that possible?
That did not work. It gives:[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 14, 15, 16, 17, 18, 19, 20, 21, 22]
I changed to:
let rangeA = 1...10
let rangeB = 14...22
let mini = min(rangeA.min()!, rangeB.min()!)
let maxi = max(rangeA.max()!, rangeB.max()!)
let allRange = mini...maxi
var missing : [Int] = Array(allRange).sorted().filter() {num in !rangeA.contains(num) && !rangeB.contains(num)}
print(missing)
And get the expected result.