How to resolve the algorithm Range consolidation step by step in the Phix programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Range consolidation step by step in the Phix programming language

Table of Contents

Problem Statement

Define a range of numbers   R,   with bounds   b0   and   b1   covering all numbers between and including both bounds.

That range can be shown as:

Given two ranges, the act of consolidation between them compares the two ranges:

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;   and show the range with the smaller lower bound to the left of other ranges when showing multiple ranges. Output the normalized result of applying consolidation to these five sets of ranges: Show all output here.

Let's start with the solution: