Add tasks for all the new languages

This commit is contained in:
Tina Müller 2016-12-05 23:44:36 +01:00
parent 9dc3c2bb62
commit bba7bfd280
13208 changed files with 134745 additions and 0 deletions

View 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

View 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

View 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 />'
^}'

View 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)

View file

@ -0,0 +1,3 @@
: mapRange(p1, p2, s)
s p1 first - p2 second p2 first - * p1 second p1 first - asFloat /
p2 first + ;

View 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

View 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)}";
}

View 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])) ;

View file

@ -0,0 +1 @@
range(0;11) | maprange([0,10]; [-1, 0])

View 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) );