How to resolve the algorithm Range consolidation step by step in the Yabasic programming language
How to resolve the algorithm Range consolidation step by step in the Yabasic 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:
Step by Step solution about How to resolve the algorithm Range consolidation step by step in the Yabasic programming language
Source code in the yabasic programming language
sub sort(tabla())
local items, i, t1, t2, s
items = arraysize(tabla(), 1)
repeat
s = true
for i = 1 to items-1
if tabla(i, 1) > tabla(i+1, 1) then
t1 = tabla(i, 1) : t2 = tabla(i, 2)
tabla(i, 1) = tabla(i + 1, 1) : tabla(i, 2) = tabla(i + 1, 2)
tabla(i + 1, 1) = t1 : tabla(i + 1, 2) = t2
s = false
end if
next
until(s)
end sub
sub normalize(tabla())
local items, i, t
items = arraysize(tabla(), 1)
for i = 1 to items
if tabla(i, 1) > tabla(i, 2) then
t = tabla(i, 1)
tabla(i, 1) = tabla(i, 2)
tabla(i, 2) = t
end if
next
sort(tabla())
end sub
sub consolidate(tabla())
local items, i
normalize(tabla())
items = arraysize(tabla(), 1)
for i = 1 to items - 1
if tabla(i + 1, 1) <= tabla(i, 2) then
tabla(i + 1, 1) = tabla(i, 1)
if tabla(i + 1, 2) <= tabla(i, 2) then
tabla(i + 1, 2) = tabla(i, 2)
end if
tabla(i, 1) = void : tabla(i, 2) = void
end if
next
end sub
// data 1, 1.1, 2.2
// data 2, 6.1, 7.2, 7.2, 8.3
// data 2, 4, 3, 2, 1
// data 4, 4, 3, 2, 1, -1, -2, 3.9, 10
data 5, 1,3, -6,-1, -4,-5, 8,2, -6,-6
void = 10^30
read items
dim tabla(items, 2)
for i = 1 to items
read tabla(i, 1), tabla(i, 2)
next
consolidate(tabla())
for i = 1 to items
if tabla(i, 1) <> void print tabla(i, 1), "..", tabla(i, 2);
next
You may also check:How to resolve the algorithm Happy numbers step by step in the Cowgol programming language
You may also check:How to resolve the algorithm Pick random element step by step in the Objeck programming language
You may also check:How to resolve the algorithm Checkpoint synchronization step by step in the Julia programming language
You may also check:How to resolve the algorithm Create a two-dimensional array at runtime step by step in the PowerShell programming language
You may also check:How to resolve the algorithm Parametric polymorphism step by step in the Rust programming language