langs a-z
This commit is contained in:
parent
db842d013d
commit
d066446780
11389 changed files with 98361 additions and 1020 deletions
18
Task/Map-range/Nemerle/map-range.nemerle
Normal file
18
Task/Map-range/Nemerle/map-range.nemerle
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
using System;
|
||||
using System.Console;
|
||||
|
||||
module Maprange
|
||||
{
|
||||
Maprange(a : double * double, b : double * double, s : double) : double
|
||||
{
|
||||
def (a1, a2) = a; def (b1, b2) = b;
|
||||
|
||||
b1 + (((s - a1) * (b2 - b1))/(a2 - a1))
|
||||
}
|
||||
|
||||
Main() : void
|
||||
{
|
||||
foreach (i in [0 .. 10])
|
||||
WriteLine("{0, 2:f0} maps to {1:f1}", i, Maprange((0.0, 10.0), (-1.0, 0.0), i));
|
||||
}
|
||||
}
|
||||
20
Task/Map-range/NetRexx/map-range.netrexx
Normal file
20
Task/Map-range/NetRexx/map-range.netrexx
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
/* NetRexx */
|
||||
options replace format comments java crossref savelog symbols nobinary
|
||||
|
||||
A = [ 0.0, 10.0 ]
|
||||
B = [ -1.0, 0.0 ]
|
||||
incr = 1.0
|
||||
|
||||
say 'Mapping ['A[0]',' A[1]'] to ['B[0]',' B[1]'] in increments of' incr':'
|
||||
loop sVal = A[0] to A[1] by incr
|
||||
say ' f('sVal.format(3, 3)') =' mapRange(A, B, sVal).format(4, 3)
|
||||
end sVal
|
||||
|
||||
return
|
||||
|
||||
method mapRange(a = Rexx[], b = Rexx[], s_) public static
|
||||
return mapRange(a[0], a[1], b[0], b[1], s_)
|
||||
|
||||
method mapRange(a1, a2, b1, b2, s_) public static
|
||||
t_ = b1 + ((s_ - a1) * (b2 - b1) / (a2 - a1))
|
||||
return t_
|
||||
8
Task/Map-range/OCaml/map-range-1.ocaml
Normal file
8
Task/Map-range/OCaml/map-range-1.ocaml
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
let map_range (a1, a2) (b1, b2) s =
|
||||
b1 +. ((s -. a1) *. (b2 -. b1) /. (a2 -. a1))
|
||||
|
||||
let () =
|
||||
print_endline "Mapping [0,10] to [-1,0] at intervals of 1:";
|
||||
for i = 0 to 10 do
|
||||
Printf.printf "f(%d) = %g\n" i (map_range (0.0, 10.0) (-1.0, 0.0) (float i))
|
||||
done
|
||||
11
Task/Map-range/OCaml/map-range-2.ocaml
Normal file
11
Task/Map-range/OCaml/map-range-2.ocaml
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
let map_range (a1, a2) (b1, b2) =
|
||||
let v = (b2 -. b1) /. (a2 -. a1) in
|
||||
function s ->
|
||||
b1 +. ((s -. a1) *. v)
|
||||
|
||||
let () =
|
||||
print_endline "Mapping [0,10] to [-1,0] at intervals of 1:";
|
||||
let p = (map_range (0.0, 10.0) (-1.0, 0.0)) in
|
||||
for i = 0 to 10 do
|
||||
Printf.printf "f(%d) = %g\n" i (p (float i))
|
||||
done
|
||||
14
Task/Map-range/Objeck/map-range.objeck
Normal file
14
Task/Map-range/Objeck/map-range.objeck
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
bundle Default {
|
||||
class Range {
|
||||
function : MapRange(a1:Float, a2:Float, b1:Float, b2:Float, s:Float) ~ Float {
|
||||
return b1 + (s-a1)*(b2-b1)/(a2-a1);
|
||||
}
|
||||
|
||||
function : Main(args : String[]) ~ Nil {
|
||||
"Mapping [0,10] to [-1,0] at intervals of 1:"->PrintLine();
|
||||
for(i := 0.0; i <= 10.0; i += 1;) {
|
||||
IO.Console->Print("f(")->Print(i->As(Int))->Print(") = ")->PrintLine(MapRange(0.0, 10.0, -1.0, 0.0, i));
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
1
Task/Map-range/PARI-GP/map-range.pari
Normal file
1
Task/Map-range/PARI-GP/map-range.pari
Normal file
|
|
@ -0,0 +1 @@
|
|||
map(r1,r2,x)=r2[1]+(x-r1[1])*(r2[2]-r2[1])/(r1[2]-r1[1])
|
||||
13
Task/Map-range/PL-I/map-range.pli
Normal file
13
Task/Map-range/PL-I/map-range.pli
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
map: procedure options (main); /* 24/11/2011 */
|
||||
declare (a1, a2, b1, b2) float;
|
||||
declare d fixed decimal (3,1);
|
||||
|
||||
do d = 0 to 10 by 0.9, 10;
|
||||
put skip edit ( d, ' maps to ', map(0, 10, -1, 0, d) ) (f(5,1), a, f(10,6));
|
||||
end;
|
||||
|
||||
map: procedure (a1, a2, b1, b2, s) returns (float);
|
||||
declare (a1, a2, b1, b2, s) float;
|
||||
return (b1 + (s - a1)*(b2 - b1) / (a2 - a1) );
|
||||
end map;
|
||||
end map;
|
||||
13
Task/Map-range/Pascal/map-range.pascal
Normal file
13
Task/Map-range/Pascal/map-range.pascal
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
Program Map(output);
|
||||
|
||||
function MapRange(fromRange, toRange: array of real; value: real): real;
|
||||
begin
|
||||
MapRange := (value-fromRange[0]) * (toRange[1]-toRange[0]) / (fromRange[1]-fromRange[0]) + toRange[0];
|
||||
end;
|
||||
|
||||
var
|
||||
i: integer;
|
||||
begin
|
||||
for i := 0 to 10 do
|
||||
writeln (i, ' maps to: ', MapRange([0.0, 10.0], [-1.0, 0.0], i):4:2);
|
||||
end.
|
||||
8
Task/Map-range/Perl-6/map-range-1.pl6
Normal file
8
Task/Map-range/Perl-6/map-range-1.pl6
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
use v6;
|
||||
# Author: P. Seebauer
|
||||
sub the_function(Range $a, Range $b, $s ) {
|
||||
my ($a1, $a2, $b1, $b2) = ($a, $b)».bounds;
|
||||
return $b1 + (($s-$a1) * ($b2-$b1) / ($a2-$a1));
|
||||
}
|
||||
|
||||
for ^11 -> $x {say "$x maps to {the_function(0..10,-1..0, $x)}"}
|
||||
7
Task/Map-range/Perl-6/map-range-2.pl6
Normal file
7
Task/Map-range/Perl-6/map-range-2.pl6
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
sub getmapper(Range $a, Range $b) {
|
||||
my ($a1, $a2, $b1, $b2) = ($a, $b)».bounds;
|
||||
return -> $s { $b1 + (($s-$a1) * ($b2-$b1) / ($a2-$a1)) }
|
||||
}
|
||||
|
||||
my &mapper = getmapper(0 .. 10, -1 .. 0);
|
||||
for ^11 -> $x {say "$x maps to &mapper($x)"}
|
||||
23
Task/Map-range/PureBasic/map-range.purebasic
Normal file
23
Task/Map-range/PureBasic/map-range.purebasic
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
Structure RR
|
||||
a.f
|
||||
b.f
|
||||
EndStructure
|
||||
|
||||
Procedure.f MapRange(*a.RR, *b.RR, s)
|
||||
Protected.f a1, a2, b1, b2
|
||||
a1=*a\a: a2=*a\b
|
||||
b1=*b\a: b2=*b\b
|
||||
ProcedureReturn b1 + ((s - a1) * (b2 - b1) / (a2 - a1))
|
||||
EndProcedure
|
||||
|
||||
|
||||
;- Test the function
|
||||
If OpenConsole()
|
||||
Define.RR Range1, Range2
|
||||
Range1\a=0: Range1\b=10
|
||||
Range2\a=-1:Range2\b=0
|
||||
;
|
||||
For i=0 To 10
|
||||
PrintN(RSet(Str(i),2)+" maps to "+StrF(MapRange(@Range1, @Range2, i),1))
|
||||
Next
|
||||
EndIf
|
||||
15
Task/Map-range/Seed7/map-range.seed7
Normal file
15
Task/Map-range/Seed7/map-range.seed7
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
$ include "seed7_05.s7i";
|
||||
include "float.s7i";
|
||||
|
||||
const func float: mapRange (in float: a1, in float: a2, in float: b1, in float: b2, ref float: s) is
|
||||
return b1 + (s-a1)*(b2-b1)/(a2-a1);
|
||||
|
||||
const proc: main is func
|
||||
local
|
||||
var integer: number is 0;
|
||||
begin
|
||||
writeln("Mapping [0,10] to [-1,0] at intervals of 1:");
|
||||
for number range 0 to 10 do
|
||||
writeln("f(" <& number <& ") = " <& mapRange(0.0, 10.0, -1.0, 0.0, flt(number)) digits 1);
|
||||
end for;
|
||||
end func;
|
||||
7
Task/Map-range/Ursala/map-range-1.ursala
Normal file
7
Task/Map-range/Ursala/map-range-1.ursala
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
#import flo
|
||||
|
||||
f((("a1","a2"),("b1","b2")),"s") = plus("b1",div(minus("s","a1"),minus("a2","a1")))
|
||||
|
||||
#cast %eL
|
||||
|
||||
test = f* ((0.,10.),(-1.,0.))-* ari11/0. 10.
|
||||
1
Task/Map-range/Ursala/map-range-2.ursala
Normal file
1
Task/Map-range/Ursala/map-range-2.ursala
Normal file
|
|
@ -0,0 +1 @@
|
|||
f(("a1","a2"),("b1","b2")) "s" = ...
|
||||
13
Task/Map-range/XPL0/map-range.xpl0
Normal file
13
Task/Map-range/XPL0/map-range.xpl0
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
include c:\cxpl\codes;
|
||||
|
||||
func real Map(A1, A2, B1, B2, S);
|
||||
real A1, A2, B1, B2, S;
|
||||
return B1 + (S-A1)*(B2-B1)/(A2-A1);
|
||||
|
||||
int I;
|
||||
[for I:= 0 to 10 do
|
||||
[if I<10 then ChOut(0, ^ ); IntOut(0, I);
|
||||
RlOut(0, Map(0., 10., -1., 0., float(I)));
|
||||
CrLf(0);
|
||||
];
|
||||
]
|
||||
Loading…
Add table
Add a link
Reference in a new issue