Add tasks for all the new languages
This commit is contained in:
parent
9dc3c2bb62
commit
bba7bfd280
13208 changed files with 134745 additions and 0 deletions
11
Task/Map-range/ERRE/map-range.erre
Normal file
11
Task/Map-range/ERRE/map-range.erre
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
PROGRAM RANGE
|
||||
|
||||
BEGIN
|
||||
AL=0 AH=10
|
||||
BL=-1 BH=0
|
||||
FOR N=0 TO 10 DO
|
||||
RANGE=BL+(N-AL)*(BH-BL)/(AH-AL)
|
||||
WRITE("### maps to ##.##";N;RANGE)
|
||||
! PRINT(N;" maps to ";RANGE)
|
||||
END FOR
|
||||
END PROGRAM
|
||||
30
Task/Map-range/EchoLisp/map-range.echolisp
Normal file
30
Task/Map-range/EchoLisp/map-range.echolisp
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
(lib 'plot) ;; interpolation functions
|
||||
(lib 'compile)
|
||||
|
||||
;; rational version
|
||||
(define (q-map-range x xmin xmax ymin ymax) (+ ymin (/ ( * (- x xmin) (- ymax ymin)) (- xmax xmin))))
|
||||
|
||||
;; float version
|
||||
(define (map-range x xmin xmax ymin ymax) (+ ymin (// ( * (- x xmin) (- ymax ymin)) (- xmax xmin))))
|
||||
; accelerate it
|
||||
(compile 'map-range "-vf")
|
||||
|
||||
(q-map-range 4 0 10 -1 0)
|
||||
→ -3/5
|
||||
(map-range 4 0 10 -1 0)
|
||||
→ -0.6
|
||||
(linear 4 0 10 -1 0) ;; native
|
||||
→ -0.6
|
||||
|
||||
(for [(x (in-range 0 10))] (writeln x (q-map-range x 0 10 -1 0) (map-range x 0 10 -1 0)))
|
||||
|
||||
0 -1 -1
|
||||
1 -9/10 -0.9
|
||||
2 -4/5 -0.8
|
||||
3 -7/10 -0.7
|
||||
4 -3/5 -0.6
|
||||
5 -1/2 -0.5
|
||||
6 -2/5 -0.4
|
||||
7 -3/10 -0.3
|
||||
8 -1/5 -0.2
|
||||
9 -1/10 -0.1
|
||||
15
Task/Map-range/Lasso/map-range.lasso
Normal file
15
Task/Map-range/Lasso/map-range.lasso
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
define map_range(
|
||||
a1,
|
||||
a2,
|
||||
b1,
|
||||
b2,
|
||||
number
|
||||
) => (decimal(#b1) + (decimal(#number) - decimal(#a1)) * (decimal(#b2) - decimal(#b1)) / (decimal(#a2) - decimal(#a1))) -> asstring(-Precision = 1)
|
||||
|
||||
with number in generateSeries(1,10) do {^
|
||||
#number
|
||||
': '
|
||||
map_range( 0, 10, -1, 0, #number)
|
||||
'<br />'
|
||||
|
||||
^}'
|
||||
10
Task/Map-range/Nim/map-range.nim
Normal file
10
Task/Map-range/Nim/map-range.nim
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
import strutils
|
||||
|
||||
type FloatRange = tuple[s,e: float]
|
||||
|
||||
proc mapRange(a,b: FloatRange, s): float =
|
||||
b.s + (s - a.s) * (b.e - b.s) / (a.e - a.s)
|
||||
|
||||
for i in 0..10:
|
||||
let m = mapRange((0.0,10.0), (-1.0, 0.0), float(i))
|
||||
echo i, " maps to ", formatFloat(m, precision = 0)
|
||||
3
Task/Map-range/Oforth/map-range.oforth
Normal file
3
Task/Map-range/Oforth/map-range.oforth
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
: mapRange(p1, p2, s)
|
||||
s p1 first - p2 second p2 first - * p1 second p1 first - asFloat /
|
||||
p2 first + ;
|
||||
7
Task/Map-range/Phix/map-range.phix
Normal file
7
Task/Map-range/Phix/map-range.phix
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
function MapRange(atom s, a1, a2, b1, b2)
|
||||
return b1+(s-a1)*(b2-b1)/(a2-a1)
|
||||
end function
|
||||
|
||||
for i=0 to 10 by 2 do
|
||||
printf(1,"%2d : %g\n",{i,MapRange(i,0,10,-1,0)})
|
||||
end for
|
||||
11
Task/Map-range/Sidef/map-range.sidef
Normal file
11
Task/Map-range/Sidef/map-range.sidef
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
func map_range(a, b, x) {
|
||||
var (a1, a2, b1, b2) = (a.bounds, b.bounds);
|
||||
x-a1 * b2-b1 / a2-a1 + b1;
|
||||
}
|
||||
|
||||
var a = 0..10;
|
||||
var b = -1..0;
|
||||
|
||||
for x in a {
|
||||
say "#{x} maps to #{map_range(a, b, x)}";
|
||||
}
|
||||
5
Task/Map-range/jq/map-range-1.jq
Normal file
5
Task/Map-range/jq/map-range-1.jq
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
# The input is the value to be mapped.
|
||||
# The ranges, a and b, should each be an array defining the
|
||||
# left-most and right-most points of the range.
|
||||
def maprange(a; b):
|
||||
b[0] + (((. - a[0]) * (b[1] - b[0])) / (a[1] - a[0])) ;
|
||||
1
Task/Map-range/jq/map-range-2.jq
Normal file
1
Task/Map-range/jq/map-range-2.jq
Normal file
|
|
@ -0,0 +1 @@
|
|||
range(0;11) | maprange([0,10]; [-1, 0])
|
||||
5
Task/Map-range/jq/map-range-3.jq
Normal file
5
Task/Map-range/jq/map-range-3.jq
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
def maprange_array(a; b):
|
||||
def _helper(a0; b0; factor): b0 + (. - a0) * factor;
|
||||
|
||||
a[0] as $a | b[0] as $b | ((b[1] - b[0]) / (a[1] - a[0])) as $factor
|
||||
| map(_helper( $a; $b; $factor) );
|
||||
Loading…
Add table
Add a link
Reference in a new issue