June 2018 Update

This commit is contained in:
Ingy döt Net 2018-06-22 20:57:24 +00:00
parent ba8067c3b7
commit 22f33d4004
5278 changed files with 84726 additions and 14379 deletions

View file

@ -1,3 +1,8 @@
maprange(s, a, b) = let a1 = minimum(a), a2 = maximum(a), b1 = minimum(b), b2 = maximum(b)
b1 + (s-a1) * (b2-b1) / (a2-a1)
function maprange(s, a, b)
a₁, a₂ = minimum(a), maximum(a)
b₁, b₂ = minimum(b), maximum(b)
return b₁ + (s - a₁) * (b₂ - b₁) / (a₂ - a₁)
end
@show maprange(6, 1:10, -1:0)
@show maprange(0:10, 0:10, -1:0)

View file

@ -0,0 +1,8 @@
Map:=proc(a1,a2,b1,b2,s);
return (b1+((s-a1)*(b2-b1)/(a2-a1)));
end proc;
for i from 0 to 10 do
printf("%a maps to ",i);
printf("%a\n",Map(0,10,-1,0,i));
end do;

View file

@ -1,11 +1,11 @@
/*REXX program maps and displays a range of numbers from one range to another range.*/
rangeA = 0 10 /*or: rangeA = ' 0 10 ' */
rangeB = -1 0 /*or: rangeB = " -1 0 " */
parse var RangeA L H
inc=1
rangeA = 0 10 /*or: rangeA = ' 0 10 ' */
rangeB = -1 0 /*or: rangeB = " -1 0 " */
parse var rangeA L H
inc= 1
do j=L to H by inc * (1 - 2 * sign(H<L) ) /*BY: either +inc or -inc */
say right(j, digits()) ' maps to ' mapRange(rangeA, rangeB, j)
say right(j, 9) ' maps to ' mapR(rangeA, rangeB, j)
end /*j*/
exit /*stick a fork in it, we're done.*/
/*──────────────────────────────────────────────────────────────────────────────────────*/
mapRange: procedure; parse arg a1 a2,b1 b2,s; return b1 + (s-a1) * (b2-b1) / (a2-a1)
mapR: procedure; parse arg a1 a2,b1 b2,s;$=b1+(s-a1)*(b2-b1)/(a2-a1);return left('',$>=0)$

View file

@ -1,11 +1,11 @@
/*REXX program maps and displays a range of numbers from one range to another range.*/
rangeA = 10 0 /*or: rangeA = ' 10 0 ' */
rangeB = -1 0 /*or: rangeB = " -1 0 " */
parse var RangeA L H /*note the LOW & HIGH values in A*/
inc= 1/2 /*use a different step size (inc)*/
do j=L to H by inc * (1 - 2 * sign(H<L) ) /*BY: either +inc or -inc */
say right(j, digits()) ' maps to ' mapRange(rangeA, rangeB, j)
rangeA = 10 0 /*or: rangeA = ' 0 10 ' */
rangeB = -1 0 /*or: rangeB = " -1 0 " */
parse var rangeA L H
inc= 1/2
do j=L to H by inc * (1 - 2 * sign(H<L) ) /*BY: either +inc or -inc */
say right(j, 9) ' maps to ' mapR(rangeA, rangeB, j)
end /*j*/
exit /*stick a fork in it, we're done.*/
/*──────────────────────────────────────────────────────────────────────────────────────*/
mapRange: procedure; parse arg a1 a2,b1 b2,s; return b1 + (s-a1) * (b2-b1) / (a2-a1)
mapR: procedure; parse arg a1 a2,b1 b2,s;$=b1+(s-a1)*(b2-b1)/(a2-a1);return left('',$>=0)$

View file

@ -1,12 +1,13 @@
/*REXX program maps and displays a range of numbers from one range to another range.*/
rangeA = 0 10
rangeB = -1 0
inc = 1
call mapRange rangeA, RangeB, inc
exit /*stick a fork in it, we're done.*/
rangeA = 0 10
rangeB = -1 0
inc = 1
call mapR rangeA, rangeB, inc
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
mapRange: procedure; parse arg a1 a2, b1 b2, inc /* [↓] BY: either +inc or -inc*/
do s=a1 to a2 by inc * (1 - 2 * sign(a2 < a1) )
say right(s,digits()) ' maps to ' b1 + (s-a1) * (b2-b1) / (a2-a1)
end /*s*/ /*↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑*/
return /*═══════════════t═══════════════*/
mapR: procedure; parse arg a1 a2, b1 b2, inc /* [↓] BY is either +inc or -inc.*/
do s=a1 to a2 by inc * (1 - 2 * sign(a2 < a1) )
t= b1 + (s-a1) * (b2-b1) / (a2-a1)
say right(s, 9) ' maps to' left('', t>=0) t
end /*s*/
return /* [↑] LEFT··· aligns non─negative #'s*/

View file

@ -1,6 +1,6 @@
/*REXX program maps a number from one range to another range. */
/* 31.10.2013 Walter Pachl */
/* 'translated' from version 1 without using Procedure */
/* 'translated' from an older version 1 without using Procedure */
do j=0 to 10
say right(j,3) ' maps to ' mapRange(0,10,-1,0,j)
end

View file

@ -3,13 +3,14 @@
# Author : Gal Zsolt (~ CalmoSoft ~)
# Email : <calmosoft@gmail.com>
decimals(1)
al = 0
ah = 10
bl = -1
bh = 0
for n = 0 to 10
see " maps to " + maprange(al, bl, n) + nl
see "" + n + " maps to " + maprange(al, bl, n) + nl
next
func maprange(al, bl, s)
return bl + (s - al) * (bh - bl) / (ah - al)
return bl + (s - al) * (bh - bl) / (ah - al)

View file

@ -0,0 +1,22 @@
program define maprange
version 15.1
syntax varname(numeric) [if] [in], ///
from(numlist min=2 max=2) to(numlist min=2 max=2) ///
GENerate(name) [REPLACE]
tempname a b c d h
sca `a'=`:word 1 of `from''
sca `b'=`:word 2 of `from''
sca `c'=`:word 1 of `to''
sca `d'=`:word 2 of `to''
sca `h'=(`d'-`c')/(`b'-`a')
cap confirm variable `generate'
if "`replace'"=="replace" & !_rc {
qui replace `generate'=(`varlist'-`a')*`h'+`c' `if' `in'
}
else {
if "`replace'"=="replace" {
di in gr `"(note: variable `generate' not found)"'
}
qui gen `generate'=(`varlist'-`a')*`h'+`c' `if' `in'
}
end

View file

@ -0,0 +1,6 @@
clear
set obs 11
gen x=_n-1
maprange x if mod(x,2)==0, gen(y) from(0 10) to(-10 10)
maprange x if mod(x,2)!=0, gen(y) from(0 10) to(-100 100) replace
list