Data update
This commit is contained in:
parent
4bb20c9b71
commit
cbaf4c4b64
12390 changed files with 318560 additions and 27248 deletions
33
Task/Map-range/Ada/map-range.adb
Normal file
33
Task/Map-range/Ada/map-range.adb
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
with Ada.Text_IO;
|
||||
procedure Map is
|
||||
type First_Range is new Float range 0.0 .. 10.0;
|
||||
type Second_Range is new Float range -1.0 .. 0.0;
|
||||
function Translate (Value : First_Range) return Second_Range is
|
||||
B1 : Float := Float (Second_Range'First);
|
||||
B2 : Float := Float (Second_Range'Last);
|
||||
A1 : Float := Float (First_Range'First);
|
||||
A2 : Float := Float (First_Range'Last);
|
||||
Result : Float;
|
||||
begin
|
||||
Result := B1 + (Float (Value) - A1) * (B2 - B1) / (A2 - A1);
|
||||
return Second_Range (Result);
|
||||
end;
|
||||
function Translate (Value : Second_Range) return First_Range is
|
||||
B1 : Float := Float (First_Range'First);
|
||||
B2 : Float := Float (First_Range'Last);
|
||||
A1 : Float := Float (Second_Range'First);
|
||||
A2 : Float := Float (Second_Range'Last);
|
||||
Result : Float;
|
||||
begin
|
||||
Result := B1 + (Float (Value) - A1) * (B2 - B1) / (A2 - A1);
|
||||
return First_Range (Result);
|
||||
end;
|
||||
Test_Value : First_Range := First_Range'First;
|
||||
begin
|
||||
loop
|
||||
Ada.Text_IO.Put_Line (First_Range'Image (Test_Value) & " maps to: "
|
||||
& Second_Range'Image (Translate (Test_Value)));
|
||||
exit when Test_Value = First_Range'Last;
|
||||
Test_Value := Test_Value + 1.0;
|
||||
end loop;
|
||||
end Map;
|
||||
8
Task/Map-range/Asymptote/map-range.asymptote
Normal file
8
Task/Map-range/Asymptote/map-range.asymptote
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
real mapRange(int s, int a1, int a2, int b1, int b2) {
|
||||
return b1 + (s - a1) * (b2 - b1) / (a2 - a1);
|
||||
}
|
||||
|
||||
for (int i = 0; i <= 10; ++i) {
|
||||
real r = mapRange(i, 0, 10, -1, 0);
|
||||
write( (string)i + " maps to " + format("%0.1f", r) );
|
||||
}
|
||||
53
Task/Map-range/COBOL/map-range.cob
Normal file
53
Task/Map-range/COBOL/map-range.cob
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
IDENTIFICATION DIVISION.
|
||||
PROGRAM-ID. demo-map-range.
|
||||
|
||||
DATA DIVISION.
|
||||
WORKING-STORAGE SECTION.
|
||||
01 i USAGE FLOAT-LONG.
|
||||
|
||||
01 mapped-num USAGE FLOAT-LONG.
|
||||
|
||||
01 a-begin USAGE FLOAT-LONG VALUE 0.
|
||||
01 a-end USAGE FLOAT-LONG VALUE 10.
|
||||
|
||||
01 b-begin USAGE FLOAT-LONG VALUE -1.
|
||||
01 b-end USAGE FLOAT-LONG VALUE 0.
|
||||
|
||||
01 i-display PIC --9.9.
|
||||
01 mapped-display PIC --9.9.
|
||||
|
||||
PROCEDURE DIVISION.
|
||||
PERFORM VARYING i FROM 0 BY 1 UNTIL i > 10
|
||||
CALL "map-range" USING CONTENT a-begin, a-end, b-begin,
|
||||
b-end, i, REFERENCE mapped-num
|
||||
COMPUTE i-display ROUNDED = i
|
||||
COMPUTE mapped-display ROUNDED = mapped-num
|
||||
DISPLAY FUNCTION TRIM(i-display) " maps to "
|
||||
FUNCTION TRIM(mapped-display)
|
||||
END-PERFORM
|
||||
.
|
||||
END PROGRAM demo-map-range.
|
||||
|
||||
|
||||
IDENTIFICATION DIVISION.
|
||||
PROGRAM-ID. map-range.
|
||||
|
||||
DATA DIVISION.
|
||||
LINKAGE SECTION.
|
||||
01 a-begin USAGE FLOAT-LONG.
|
||||
01 a-end USAGE FLOAT-LONG.
|
||||
|
||||
01 b-begin USAGE FLOAT-LONG.
|
||||
01 b-end USAGE FLOAT-LONG.
|
||||
|
||||
01 val-to-map USAGE FLOAT-LONG.
|
||||
|
||||
01 ret USAGE FLOAT-LONG.
|
||||
|
||||
PROCEDURE DIVISION USING a-begin, a-end, b-begin, b-end,
|
||||
val-to-map, ret.
|
||||
COMPUTE ret =
|
||||
b-begin + ((val-to-map - a-begin) * (b-end - b-begin)
|
||||
/ (a-end - a-begin))
|
||||
.
|
||||
END PROGRAM map-range.
|
||||
10
Task/Map-range/Chipmunk-Basic/map-range.basic
Normal file
10
Task/Map-range/Chipmunk-Basic/map-range.basic
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
100 cls
|
||||
110 for i = 0 to 10
|
||||
120 print using "##";i;
|
||||
130 print " maps to ";
|
||||
140 print using "##.#";maprange(i,0,10,-1,0)
|
||||
150 next i
|
||||
160 end
|
||||
170 function maprange(s,a1,a2,b1,b2)
|
||||
180 maprange = b1+(s-a1)*(b2-b1)/(a2-a1)
|
||||
190 end function
|
||||
10
Task/Map-range/Crystal/map-range.cr
Normal file
10
Task/Map-range/Crystal/map-range.cr
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
def map_range (s, from, to)
|
||||
a1, a2 = from.begin, from.end
|
||||
b1, b2 = to.begin, to.end
|
||||
|
||||
b1 + ( (s - a1) * (b2 - b1) ) / (a2 - a1)
|
||||
end
|
||||
|
||||
(0..10).each do |i|
|
||||
printf " %2d -> %g\n", i, map_range(i, 0..10, -1..0)
|
||||
end
|
||||
10
Task/Map-range/Dart/map-range.dart
Normal file
10
Task/Map-range/Dart/map-range.dart
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
double mapRange(int s, int a1, int a2, int b1, int b2) {
|
||||
return b1 + (s - a1) * (b2 - b1) / (a2 - a1);
|
||||
}
|
||||
|
||||
void main() {
|
||||
for (int i = 0; i <= 10; i++) {
|
||||
double r = mapRange(i, 0, 10, -1, 0);
|
||||
print("${i.toString().padLeft(2)} maps to ${r.toStringAsFixed(1)}");
|
||||
}
|
||||
}
|
||||
5
Task/Map-range/Emacs-Lisp/map-range.el
Normal file
5
Task/Map-range/Emacs-Lisp/map-range.el
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
(defun maprange (a1 a2 b1 b2 s)
|
||||
(+ b1 (/ (* (- s a1) (- b2 b1)) (- a2 a1))))
|
||||
|
||||
(dotimes (i 10)
|
||||
(message "%s" (maprange 0.0 10.0 -1.0 0.0 i)))
|
||||
7
Task/Map-range/Euphoria/map-range.eu
Normal file
7
Task/Map-range/Euphoria/map-range.eu
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
function map_range(sequence a, sequence b, atom s)
|
||||
return b[1]+(s-a[1])*(b[2]-b[1])/(a[2]-a[1])
|
||||
end function
|
||||
|
||||
for i = 0 to 10 do
|
||||
printf(1, "%2g maps to %4g\n", {i, map_range({0,10},{-1,0},i)})
|
||||
end for
|
||||
15
Task/Map-range/Gambas/map-range.gambas
Normal file
15
Task/Map-range/Gambas/map-range.gambas
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
Function MapRange(s As Integer, a1 As Integer, a2 As Integer, b1 As Integer, b2 As Integer) As Float
|
||||
|
||||
Return b1 + (s - a1) * (b2 - b1) / (a2 - a1)
|
||||
|
||||
End Function
|
||||
|
||||
Public Sub Main()
|
||||
|
||||
Dim i As Integer
|
||||
|
||||
For i = 0 To 10
|
||||
Print Format$(i, "##"); " maps to "; Format$(MapRange(i, 0, 10, -1, 0), "+##.0")
|
||||
Next
|
||||
|
||||
End Sub
|
||||
7
Task/Map-range/MSX-Basic/map-range.basic
Normal file
7
Task/Map-range/MSX-Basic/map-range.basic
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
10 CLS
|
||||
20 DEF FN MR(S) = B1 + (S - A1) * (B2 - B1) / (A2 - A1)
|
||||
30 A1 = 0: A2 = 10: B1 = -1: B2 = 0
|
||||
40 FOR X = A1 TO A2
|
||||
50 PRINT X; "maps to "; FN MR(X)
|
||||
60 NEXT X
|
||||
70 END
|
||||
12
Task/Map-range/Pluto/map-range.pluto
Normal file
12
Task/Map-range/Pluto/map-range.pluto
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
local fmt = require "fmt"
|
||||
|
||||
local function map_range(a, b, s)
|
||||
return b[1] + (s - a[1]) * (b:back() - b[1]) / (a:back() - a[1])
|
||||
end
|
||||
|
||||
local a = range(0, 10)
|
||||
local b = range(-1, 0)
|
||||
for a as s do
|
||||
local t = map_range(a, b, s)
|
||||
fmt.print("%2d maps to % g", s, t)
|
||||
end
|
||||
36
Task/Map-range/PowerShell/map-range-1.ps1
Normal file
36
Task/Map-range/PowerShell/map-range-1.ps1
Normal 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])
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
1
Task/Map-range/PowerShell/map-range-2.ps1
Normal file
1
Task/Map-range/PowerShell/map-range-2.ps1
Normal file
|
|
@ -0,0 +1 @@
|
|||
0..10 | Group-Range (0,10) (-1,0)
|
||||
10
Task/Map-range/Prolog/map-range.pro
Normal file
10
Task/Map-range/Prolog/map-range.pro
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
% map_range(+S, +A1, +A2, +B1, +B2, -R)
|
||||
map_range(S, A1, A2, B1, B2, R) :-
|
||||
R is B1 + (S - A1) * (B2 - B1) / (A2 - A1).
|
||||
|
||||
% bucle principal
|
||||
run :-
|
||||
forall(between(0, 10, I),
|
||||
( map_range(I, 0, 10, -1, 0, R),
|
||||
format("~w maps to ~1f~n", [I, R])
|
||||
)).
|
||||
|
|
@ -1,19 +0,0 @@
|
|||
>>> def maprange( a, b, s):
|
||||
(a1, a2), (b1, b2) = a, b
|
||||
return b1 + ((s - a1) * (b2 - b1) / (a2 - a1))
|
||||
|
||||
>>> for s in range(11):
|
||||
print("%2g maps to %g" % (s, maprange( (0, 10), (-1, 0), s)))
|
||||
|
||||
|
||||
0 maps to -1
|
||||
1 maps to -0.9
|
||||
2 maps to -0.8
|
||||
3 maps to -0.7
|
||||
4 maps to -0.6
|
||||
5 maps to -0.5
|
||||
6 maps to -0.4
|
||||
7 maps to -0.3
|
||||
8 maps to -0.2
|
||||
9 maps to -0.1
|
||||
10 maps to 0
|
||||
|
|
@ -1,17 +0,0 @@
|
|||
>>> from fractions import Fraction
|
||||
>>> for s in range(11):
|
||||
print("%2g maps to %s" % (s, maprange( (0, 10), (-1, 0), Fraction(s))))
|
||||
|
||||
|
||||
0 maps to -1
|
||||
1 maps to -9/10
|
||||
2 maps to -4/5
|
||||
3 maps to -7/10
|
||||
4 maps to -3/5
|
||||
5 maps to -1/2
|
||||
6 maps to -2/5
|
||||
7 maps to -3/10
|
||||
8 maps to -1/5
|
||||
9 maps to -1/10
|
||||
10 maps to 0
|
||||
>>>
|
||||
16
Task/Map-range/Python/map-range.py
Normal file
16
Task/Map-range/Python/map-range.py
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
from fractions import Fraction
|
||||
|
||||
def map_range(a, b, s):
|
||||
(a1, a2), (b1, b2) = a, b
|
||||
return b1 + ((s - a1) * (b2 - b1) / (a2 - a1))
|
||||
|
||||
for s in range(11):
|
||||
print(f"{s:2g} maps to {map_range((0, 10), (-1, 0), s):g}")
|
||||
|
||||
print()
|
||||
|
||||
# Because of Python's strict, dynamic typing rules for numbers, the same
|
||||
# function can give answers as fractions.
|
||||
|
||||
for s in range(11):
|
||||
print(f"{s:2g} maps to {map_range((0, 10), (-1, 0), Fraction(s))}")
|
||||
10
Task/Map-range/ReScript/map-range-1.res
Normal file
10
Task/Map-range/ReScript/map-range-1.res
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
let map_range = ((a1, a2), (b1, b2), s) => {
|
||||
b1 +. ((s -. a1) *. (b2 -. b1) /. (a2 -. a1))
|
||||
}
|
||||
|
||||
Js.log("Mapping [0,10] to [-1,0] at intervals of 1:")
|
||||
|
||||
for i in 0 to 10 {
|
||||
Js.log("f(" ++ Js.String.make(i) ++ ") = " ++
|
||||
Js.String.make(map_range((0.0, 10.0), (-1.0, 0.0), float(i))))
|
||||
}
|
||||
15
Task/Map-range/ReScript/map-range-2.res
Normal file
15
Task/Map-range/ReScript/map-range-2.res
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>ReScript: Map_range</title>
|
||||
<meta charset="UTF-8"/>
|
||||
<style rel="stylesheet" type="text/css">
|
||||
body { color:#EEE; background-color:#888; }
|
||||
</style>
|
||||
<script>var exports = {};</script>
|
||||
<script src="./maprange.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
16
Task/Map-range/V-(Vlang)/map-range.v
Normal file
16
Task/Map-range/V-(Vlang)/map-range.v
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
struct Range_Bounds {
|
||||
b1 f64
|
||||
b2 f64
|
||||
}
|
||||
|
||||
fn map_range(x Range_Bounds, y Range_Bounds, n f64) f64 {
|
||||
return y.b1 + (n - x.b1) * (y.b2 - y.b1) / (x.b2 - x.b1)
|
||||
}
|
||||
|
||||
fn main() {
|
||||
r1 := Range_Bounds{0, 10}
|
||||
r2 := Range_Bounds{-1, 0}
|
||||
for n := 0; n <= 10; n += 2 {
|
||||
println("${n} maps to ${map_range(r1, r2, n):.2}")
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue