Anonymous user
Range consolidation: Difference between revisions
→{{header|Dyalect}}
Line 506:
{{trans|C#}}
<lang dyalect>
func Pt.min() => min(this::s, this::e)
x▼
func Pt.max() => max(this::s, this::e)
y▼
let rng =
[ Pt(1.1, 2.2) ],
x▼
]
func overlap(left, right) =>
right.max() >= left.min()
when left.max() > right.max()
func consolidate(left, right)
func normalize(range)
for list in
▲ [ (s: 6.1, e: 7.2), (s: 7.2, e: 8.3) ],
▲ [ (s: 4.0, e: 3.0), (s: 2, e: 1) ],
▲ [ (s: 4.0, e: 3.0), (s: 2, e: 1), (s: -1, e: 2), (s: 3.9, e: 10) ],
▲ [ (s: 1.0, e: 3.0), (s: -6, e: -1), (s: -4, e: -5), (s: 8, e: 2), (s: -6, e: -6) ]
while z >= 1 {
for y in (z - 1)^-1..0 when overlap(list[z], list[y]) {
}
z -= 1
}
for i in list.indices() {
list[i] = normalize(list[i])
}
list.sort((x,y) => x::s - y::s)
print(list)
|