Jump to content

Range consolidation: Difference between revisions

m
added whitespace and hightlighting.
(Add Factor)
m (added whitespace and hightlighting.)
Line 1:
{{task}}
 
Define a range of numbers <code>&nbsp; '''R</code>''', &nbsp; with bounds <code>&nbsp; '''b0</code>''' &nbsp; and <code>&nbsp; '''b1</code>''' &nbsp; covering all numbers ''between and including both bounds''. That range can be shown as:<br>
 
: <code>[b0, b1]</code><br>
 
or equally as:<br>
That range can be shown as:
: <code>[b1, b0]</code>.
::::::::: '''[b0, b1]'''
:::::::: &nbsp;&nbsp; or equally as:
::::::::: '''[b1, b0]'''
 
 
Given two ranges, the act of consolidation between them compares the two ranges:
* &nbsp; If one range covers all of the other then the result is that encompassing range.
* &nbsp; If the ranges touch or intersect then the result is &nbsp; ''one'' &nbsp; new single range covering the overlapping ranges.
* &nbsp; Otherwise the act of consolidation is to return the two non-touching ranges.
 
 
Given &nbsp; '''N''' &nbsp; ranges where &nbsp; '''N > 2''' &nbsp; then the result is the same as repeatedly replacing all combinations of two ranges by their consolidation until no further consolidation between range pairs is possible. If N<2 then range consolidation has no strict meaning and the input can be returned.
 
If &nbsp; '''N < 2''' &nbsp; then range consolidation has no strict meaning and the input can be returned.
 
 
;'''Example 1:'''
: &nbsp; Given the two ranges <tt>&nbsp; '''[1, 2.5]</tt>''' &nbsp; and <tt>&nbsp; '''[3, 4.2]</tt>''' &nbsp; then there is no
: &nbsp; there is no common region between the ranges and the result is the same as the input.
 
 
;'''Example 2:'''
: &nbsp; Given the two ranges <tt>&nbsp; '''[1, 2.5]</tt>''' &nbsp; and <tt>&nbsp; '''[1.8, 4.7]</tt>''' &nbsp; then there is
: &nbsp; there is : &nbsp; an overlap &nbsp; '''[2.5, 1.8]''' &nbsp; between the ranges and
:touch at <tt>7.2</tt> and&nbsp; the result is the single range <tt>&nbsp; '''[6.1, 84.37]</tt>'''.
:range <tt>[1, 4.7]</tt>. &nbsp; Note that order of bounds in a range is not, (yet), stated.
 
 
;'''Example 3:'''
: &nbsp; Given the two ranges <tt>&nbsp; '''[6.1, 7.2]</tt>''' &nbsp; and <tt>&nbsp; '''[7.2, 8.3]</tt>''' &nbsp; then they
: &nbsp; they touch at &nbsp; '''7.2''' &nbsp; and
: &nbsp; the result is the single range &nbsp; '''[6.1, 8.3]'''.
 
 
;'''Example 4:'''
: &nbsp; Given the three ranges <tt>&nbsp; '''[1, 2]</tt>''' &nbsp; and <tt>&nbsp; '''[4, 8]</tt>''' &nbsp; and <tt>&nbsp; '''[2, 5]</tt>'''
: &nbsp; then there is no intersection of the ranges <tt>&nbsp; '''[1, 2]</tt>''' &nbsp; and <tt>&nbsp; '''[4, 8]</tt>'''
: &nbsp; but the ranges <tt>&nbsp; '''[1, 2]</tt>''' &nbsp; and <tt>&nbsp; '''[2, 5]</tt>''' &nbsp; overlap and consolidate to
: &nbsp; consolidate to produce the range &nbsp; '''[1, 5]'''.
:produce the range <tt>[1, 5]</tt>.&nbsp; This range, in turn, overlaps the other range &nbsp; '''[4, 8]''', &nbsp; and
:<tt>[4, 8]</tt>, and&nbsp; so consolidates to the final output of the single range &nbsp; '''[1, 8]'''.
 
 
;'''Task:'''
Given N ranges where N>2 then the result is the same as repeatedly replacing all combinations of two ranges by their consolidation until no further consolidation between range pairs is possible. If N<2 then range consolidation has no strict meaning and the input can be returned.
Let a normalized range display show the smaller bound to the left; &nbsp; and show the
range with the smaller lower bound to the left of other ranges when showing multiple ranges.
 
Output the ''normalisednormalized'' result of applying consolidation to these five sets of ranges: <big>
;'''Example 1:'''
[1.1, 2.2]
:Given the two ranges <tt>[1, 2.5]</tt> and <tt>[3, 4.2]</tt> then there is no
[6.1, 7.2], [7.2, 8.3]
:common region between the ranges and the result is the same as the input.
[4, 3], [2, 1]
;'''Example 2:'''
[4, 3], [2, 1], [-1, -2], [3.9, 10]
:Given the two ranges <tt>[1, 2.5]</tt> and <tt>[1.8, 4.7]</tt> then there is
[1, 3], [-6, -1], [-4, -5], [8, 2], [-6, -6] </big>
:an overlap <tt>[2.5, 1.8]</tt> between the ranges and the result is the single
Show all output here.
:range <tt>[1, 4.7]</tt>. Note that order of bounds in a range is not, (yet), stated.
;'''Example 3:'''
:Given the two ranges <tt>[6.1, 7.2]</tt> and <tt>[7.2, 8.3]</tt> then they
:touch at <tt>7.2</tt> and the result is the single range <tt>[6.1, 8.3]</tt>.
;'''Example 4:'''
:Given the three ranges <tt>[1, 2]</tt> and <tt>[4, 8]</tt> and <tt>[2, 5]</tt>
:then there is no intersection of the ranges <tt>[1, 2]</tt> and <tt>[4, 8]</tt>
:but the ranges <tt>[1, 2]</tt> and <tt>[2, 5]</tt> overlap and consolidate to
:produce the range <tt>[1, 5]</tt>. This range, in turn, overlaps the other range
:<tt>[4, 8]</tt>, and so consolidates to the final output of the single range
:<tt>[1, 8]</tt>
 
;'''Task:'''
Let a normalized range display show the smaller bound to the left; and show the
range with the smaller lower bound to the left of other ranges when showing multiple
ranges.
 
''';See also''':
Output the ''normalised'' result of applying consolidation to these five sets of ranges:
<pre>
[1.1, 2.2]
[6.1, 7.2], [7.2, 8.3]
[4, 3], [2, 1]
[4, 3], [2, 1], [-1, -2], [3.9, 10]
[1, 3], [-6, -1], [-4, -5], [8, 2], [-6, -6]
</pre>
Show output here.
<br>
<br>
'''See also'''
* [[Set consolidation]]
* [[Set of real numbers]]
Cookies help us deliver our services. By using our services, you agree to our use of cookies.