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,7 @@
(define (Δ-1 list)
(for/list ([x (cdr list)] [y list]) (- x y)))
(define (Δ-n n) (iterate Δ-1 n))
((Δ-n 9) '(90 47 58 29 22 32 55 5 55 73))
→ (-2921)

View file

@ -0,0 +1,16 @@
#!/usr/bin/lasso9
define forwardDiff(values, order::integer=1) => {
!#order ? return #values->asArray
local(result = array)
iterate(#values) => {
loop_count < #values->size ?
#result->insert(#values->get(loop_count+1) - #values->get(loop_count))
}
#order > 1 ? #result = forwardDiff(#result, #order-1)
return #result
}
local(data = (:90, 47, 58, 29, 22, 32, 55, 5, 55, 73))
with x in generateSeries(0, #data->size-1)
do stdoutnl(#x + ': ' + forwardDiff(#data, #x))

View file

@ -0,0 +1,13 @@
proc dif(s): seq[int] =
result = newSeq[int](s.len-1)
for i, x in s[1..s.high]:
result[i] = x - s[i]
proc difn(s, n): seq[int] =
if n > 0: difn(dif(s), n-1)
else: s
const s = @[90, 47, 58, 29, 22, 32, 55, 5, 55, 73]
echo difn(s, 0)
echo difn(s, 1)
echo difn(s, 2)

View file

@ -0,0 +1,2 @@
: forwardDiff(l) l right(l size 1 -) l zipWith(#-) ;
: forwardDiffN(n, l) l #[ forwardDiff dup println ] times(n) ;

View file

@ -0,0 +1,15 @@
func dif(arr) {
gather {
range(0, arr.end-1).each { |i|
take(arr[i+1] - arr[i]);
}
}
}
func difn(n, arr) {
n.times { arr = dif(arr) };
arr;
}
say dif([1, 23, 45, 678]); # => [22, 22, 633]
say difn(2, [1, 23, 45, 678]); # => [0, 611]

View file

@ -0,0 +1,37 @@
#DEFINE CTAB CHR(9)
LOCAL lcList As String, i As Integer, n As Integer
n = 10
LOCAL ARRAY aa[n]
CLEAR
lcList = "90,47,58,29,22,32,55,5,55,73"
FOR i = 1 TO n
aa[i] = VAL(GETWORDNUM(lcList, i, ","))
ENDFOR
ShowOutput("Original", @aa)
k = n - 1
FOR i = 1 TO n - 1
ForwardDiff(@aa)
ShowOutput("Difference " + TRANSFORM(i), @aa)
ENDFOR
PROCEDURE ForwardDiff(a)
LOCAL i As Integer, n As Integer
n = ALEN(a)
LOCAL ARRAY b[n-1]
FOR i = 1 TO n - 1
b[i] = a[i+1] - a[i]
ENDFOR
DIMENSION a[n-1]
ACOPY(b, a)
ENDPROC
PROCEDURE ShowOutput(lcLabel, zz)
LOCAL i As Integer, n As Integer, lcTxt As String
n = ALEN(zz)
lcTxt = lcLabel + ":" + CTAB
FOR i = 1 TO n
lcTxt = lcTxt + TRANSFORM(zz[i]) + CTAB
ENDFOR
lcTxt = LEFT(lcTxt, LEN(lcTxt) - 1)
? lcTxt
ENDPROC

View file

@ -0,0 +1,8 @@
# If n is a non-negative number and if input is
# a (possibly empty) array of numbers,
# emit an array, even if the input list is too short:
def ndiff(n):
if n==0 then .
elif n == 1 then . as $in | [range(1;length) | $in[.] - $in[.-1]]
else ndiff(1) | ndiff(n-1)
end;

View file

@ -0,0 +1,3 @@
def s: [90, 47, 58, 29, 22, 32, 55, 5, 55, 73];
range(0;12) as $i | (s|ndiff($i))

View file

@ -0,0 +1,13 @@
$ jq -c -n -f forward-difference.jq
[90,47,58,29,22,32,55,5,55,73]
[-43,11,-29,-7,10,23,-50,50,18]
[54,-40,22,17,13,-73,100,-32]
[-94,62,-5,-4,-86,173,-132]
[156,-67,1,-82,259,-305]
[-223,68,-83,341,-564]
[291,-151,424,-905]
[-442,575,-1329]
[1017,-1904]
[-2921]
[]
[]