RosettaCodeData/Task/Map-range/REXX/map-range-1.rexx

12 lines
936 B
Rexx
Raw Permalink Normal View History

2016-12-05 22:15:40 +01:00
/*REXX program maps and displays a range of numbers from one range to another range.*/
2018-06-22 20:57:24 +00:00
rangeA = 0 10 /*or: rangeA = ' 0 10 ' */
rangeB = -1 0 /*or: rangeB = " -1 0 " */
parse var rangeA L H
inc= 1
2016-12-05 22:15:40 +01:00
do j=L to H by inc * (1 - 2 * sign(H<L) ) /*BY: either +inc or -inc */
2018-06-22 20:57:24 +00:00
say right(j, 9) ' maps to ' mapR(rangeA, rangeB, j)
2013-04-10 21:29:02 -07:00
end /*j*/
2016-12-05 22:15:40 +01:00
exit /*stick a fork in it, we're done.*/
/*──────────────────────────────────────────────────────────────────────────────────────*/
2018-06-22 20:57:24 +00:00
mapR: procedure; parse arg a1 a2,b1 b2,s;$=b1+(s-a1)*(b2-b1)/(a2-a1);return left('',$>=0)$