Jump to content

Map range: Difference between revisions

Hope that looks nice while being clear/easily readable?
(→‎Tcl: Added implementation)
(Hope that looks nice while being clear/easily readable?)
Line 1:
{{draft task}}Given two [[wp:Interval (mathematics)|ranges]]:, <math>[a1,a2]</math> and <math>[b1,b2]</math>, and a value <math>s</math> in range
 
* Range <math>a</math> of all real numbers <math>x</math> satisfying <math>a1 \le x \le a2</math>.
*Then Anda rangevalue <math>bs</math> ofin all real numbersrange <math>yA</math> satisfyingis linearly mapped to a value <math>b1t</math> \lein yrange \le b2<math>B</math>. where:
Then a value s in range a is linearly mapped to a value t in range b where:
:<math>t = b1 + {(s - a1)(b2 - b1) \over (a2 - a1)}</math>
 
The task is to write a function/subroutine/... that takes two ranges and a real number, and returns the mapping of the real number from the first to the second range. Use this function to map the values of the integers <math>0 to ..10</math> from the range <math>[0, 10]</math> to the range <math>[-1\neg1, 0]</math>.
 
'''Extra credit:''' Show additional idiomatic ways of performing the mapping, using tools available to the language.
Cookies help us deliver our services. By using our services, you agree to our use of cookies.