September 2017 Update

This commit is contained in:
Ingy döt Net 2017-09-23 10:01:46 +02:00
parent bba7bfd280
commit ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions

View file

@ -1,7 +0,0 @@
b + 8a 2b + 7a b + 2a 4b + 5a 5b + 4a
[(1,a), (2,------), (3,-------), (4,------), (5,-------), (6,-------),
9 9 3 9 9
2b + a 7b + 2a 8b + a
(7,------), (8,-------), (9,------), (10,b)]
3 9 9
Type: List(Tuple(Fraction(Polynomial(Integer))))

View file

@ -0,0 +1,9 @@
10 REM MAP RANGE
20 REM COMMODORE BASIC 2.0
30 REM ================================
40 A1 = 0 : A2 = 10
50 B1 = -1 : B2 = 0
60 DEF FN MR(S)=B1+(S-A1)*(B2-B1)/(A2-A1)
70 FOR S=0 TO 10
80 PRINT S;"MAPS TO ";FN MR(S)
90 NEXT

View file

@ -0,0 +1,16 @@
/* map s from [a, b] to [c, d] */
define m(a, b, c, d, s) {
return (c + (s - a) * (d - c) / (b - a))
}
scale = 6 /* division to 6 decimal places */
"[0, 10] => [-1, 0]
"
for (i = 0; i <= 10; i += 2) {
/*
* If your bc(1) has a print statement, you can try
* print i, " => ", m(0, 10, -1, 0, i), "\n"
*/
i; " => "; m(0, 10, -1, 0, i)
}
quit

View file

@ -1,19 +0,0 @@
#include <stdio.h>
double mapRange(double a1,double a2,double b1,double b2,double s)
{
return b1 + (s-a1)*(b2-b1)/(a2-a1);
}
int main()
{
int i;
puts("Mapping [0,10] to [-1,0] at intervals of 1:");
for(i=0;i<=10;i++)
{
printf("f(%d) = %g\n",i,mapRange(0,10,-1,0,i));
}
return 0;
}

View file

@ -1,12 +0,0 @@
Mapping [0,10] to [-1,0] at intervals of 1:
f(0) = -1
f(1) = -0.9
f(2) = -0.8
f(3) = -0.7
f(4) = -0.6
f(5) = -0.5
f(6) = -0.4
f(7) = -0.3
f(8) = -0.2
f(9) = -0.1
f(10) = 0

View file

@ -1,21 +1,28 @@
import Data.Ratio
import Text.Printf
import Text.Printf (PrintfType, printf)
-- Map a value from the range [a1,a2] to the range [b1,b2]. We don't check
-- for empty ranges.
mapRange :: (Fractional a) => (a, a) -> (a, a) -> a -> a
mapRange (a1,a2) (b1,b2) s = b1+(s-a1)*(b2-b1)/(a2-a1)
mapRange
:: Fractional a
=> (a, a) -> (a, a) -> a -> a
mapRange (a1, a2) (b1, b2) s = b1 + (s - a1) * (b2 - b1) / (a2 - a1)
main = do
-- Perform the mapping over floating point numbers.
main :: IO ()
main
-- Perform the mapping over floating point numbers.
= do
putStrLn "---------- Floating point ----------"
mapM_ (\n -> prtD n . mapRange (0,10) (-1,0) $ fromIntegral n) [0..10]
mapM_ (\n -> prtD n . mapRange (0, 10) (-1, 0) $ fromIntegral n) [0 .. 10]
-- Perform the same mapping over exact rationals.
putStrLn "---------- Rationals ----------"
mapM_ (\n -> prtR n . mapRange (0,10) (-1,0) $ n%1) [0..10]
where prtD :: PrintfType r => Integer -> Double -> r
prtD n x = printf "%2d -> %6.3f\n" n x
prtR :: PrintfType r => Integer -> Rational -> r
prtR n x = printf "%2d -> %s\n" n (show x)
mapM_ (\n -> prtR n . mapRange (0, 10) (-1, 0) $ n % 1) [0 .. 10]
where
prtD
:: PrintfType r
=> Integer -> Double -> r
prtD = printf "%2d -> %6.3f\n"
prtR
:: PrintfType r
=> Integer -> Rational -> r
prtR n x = printf "%2d -> %s\n" n (show x)

View file

@ -0,0 +1,16 @@
// version 1.0.6
class FloatRange(override val start: Float, override val endInclusive: Float) : ClosedRange<Float>
fun mapRange(range1: FloatRange, range2: FloatRange, value: Float): Float {
if (value !in range1) throw IllegalArgumentException("value is not within the first range")
if (range1.endInclusive == range1.start) throw IllegalArgumentException("first range cannot be single-valued")
return range2.start + (value - range1.start) * (range2.endInclusive - range2.start) / (range1.endInclusive - range1.start)
}
fun main(args: Array<String>) {
for (i in 0..10) {
val mappedValue = mapRange(FloatRange(0.0f, 10.0f), FloatRange(-1.0f, 0.0f), i.toFloat())
println(String.format("%2d maps to %+4.2f", i, mappedValue))
}
}

View file

@ -0,0 +1,36 @@
function Group-Range
{
[CmdletBinding()]
[OutputType([PSCustomObject])]
Param
(
[Parameter(Mandatory=$true,
Position=0)]
[ValidateCount(2,2)]
[double[]]
$Range1,
[Parameter(Mandatory=$true,
Position=1)]
[ValidateCount(2,2)]
[double[]]
$Range2,
[Parameter(Mandatory=$true,
ValueFromPipeline=$true,
Position=2)]
[double]
$Map
)
Process
{
foreach ($number in $Map)
{
[PSCustomObject]@{
Index = $number
Mapping = $Range2[0] + ($number - $Range1[0]) * ($Range2[0] - $Range2[1]) / ($Range1[0] - $Range1[1])
}
}
}
}

View file

@ -0,0 +1 @@
0..10 | Group-Range (0,10) (-1,0)

View file

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

View file

@ -0,0 +1,15 @@
# Project : Map range
# Date : 2017/09/20
# Author : Gal Zsolt (~ CalmoSoft ~)
# Email : <calmosoft@gmail.com>
al = 0
ah = 10
bl = -1
bh = 0
for n = 0 to 10
see " maps to " + maprange(al, bl, n) + nl
next
func maprange(al, bl, s)
return bl + (s - al) * (bh - bl) / (ah - al)

View file

@ -0,0 +1,7 @@
fcn mapRange([(a1,a2)], [(b1,b2)], s) // a1a2 is List(a1,a2)
{ b1 + ((s - a1) * (b2 - b1) / (a2 - a1)) }
r1:=T(0.0, 10.0); r2:=T(-1.0, 0.0);
foreach s in ([0.0 .. 10]){
"%2d maps to %5.2f".fmt(s,mapRange(r1,r2, s)).println();
}