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,12 @@
constant m = {{7, 8, 7},{4, 0, 9}},
m2 = {{4, 5, 1},{6, 2, 1}}
?{m,"+",m2,"=",sq_add(m,m2)}
?{m,"-",m2,"=",sq_sub(m,m2)}
?{m,"*",m2,"=",sq_mul(m,m2)}
?{m,"/",m2,"=",sq_div(m,m2)}
?{m,"^",m2,"=",sq_power(m,m2)}
?{m,"+ 3 =",sq_add(m,3)}
?{m,"- 3 =",sq_sub(m,3)}
?{m,"* 3 =",sq_mul(m,3)}
?{m,"/ 3 =",sq_div(m,3)}
?{m,"^ 3 =",sq_power(m,3)}

View file

@ -0,0 +1,12 @@
# Occurrences of .[0] in "operator" will refer to an element in self,
# and occurrences of .[1] will refer to the corresponding element in other.
def elementwise( operator; other ):
length as $rows
| if $rows == 0 then .
else . as $self
| other as $other
| ($self[0]|length) as $cols
| reduce range(0; $rows) as $i
([]; reduce range(0; $cols) as $j
(.; .[$i][$j] = ([$self[$i][$j], $other[$i][$j]] | operator) ) )
end ;

View file

@ -0,0 +1,4 @@
[[3,1,4],[1,5,9]] as $m1 | [[2,7,1],[8,2,2]] as $m2
| ( ($m1|elementwise(.[0] + .[1]; $m2) ),
($m1|elementwise(.[0] + 2 * .[1]; $m2) ),
($m1|elementwise(.[0] < .[1]; $m2) ) )

View file

@ -0,0 +1,3 @@
[[5,8,5],[9,7,11]]
[[7,15,6],[17,9,13]]
[[false,true,false],[true,false,false]]

View file

@ -0,0 +1,23 @@
def elementwise2( operator; other ):
def pow(i): . as $in | reduce range(0;i) as $i (1; .*$in);
def operation(x; op; y):
[x,y] | op as $op
| if $op == "+" then x+y
elif $op == "-" then x-y
elif $op == "*" then x*y
elif $op == "/" then x/y
elif $op == "%" then x%y
elif $op == "//" then x/y|floor
elif $op == "**" or $op == "^" or $op == "pow" then x|pow(y)
else $op
end;
length as $rows
| if $rows == 0 then .
else . as $self
| other as $other
| ($self[0]|length) as $cols
| reduce range(0; $rows) as $i
([]; reduce range(0; $cols) as $j
(.; .[$i][$j] = operation($self[$i][$j]; operator; $other[$i][$j] ) ) )
end;

View file

@ -0,0 +1,4 @@
[[3,1,4],[1,5,9]] as $m1 | [[2,7,1],[8,2,2]] as $m2
| ( ($m1|elementwise2("+"; $m2) ),
($m1|elementwise2("//"; $m2)),
($m1|elementwise2(.[0] < .[1]; $m2) ) )

View file

@ -0,0 +1,3 @@
[[5,8,5],[9,7,11]]
[[1,0,4],[0,2,4]]
[[false,true,false],[true,false,false]]