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,10 @@
(lib 'matrix)
(define M (list->array (iota 6) 3 2))
(array-print M)
0 1
2 3
4 5
(array-print (matrix-transpose M))
0 2 4
1 3 5

View file

@ -0,0 +1,2 @@
Idris> transpose [[1,2],[3,4],[5,6]]
[[1, 3, 5], [2, 4, 6]] : List (List Integer)

View file

@ -0,0 +1,13 @@
(defun transpose (matrix)
(transpose matrix '()))
(defun transpose (matrix acc)
(cond
((lists:any
(lambda (x) (== x '()))
matrix)
acc)
('true
(let ((heads (lists:map #'car/1 matrix))
(tails (lists:map #'cdr/1 matrix)))
(transpose tails (++ acc `(,heads)))))))

View file

@ -0,0 +1,8 @@
> (transpose '((1 2 3)
(4 5 6)
(7 8 9)
(10 11 12)
(13 14 15)
(16 17 18)))
((1 4 7 10 13 16) (2 5 8 11 14 17) (3 6 9 12 15 18))
>

View file

@ -0,0 +1,13 @@
proc transpose[X, Y; T](s: array[Y, array[X, T]]): array[X, array[Y, T]] =
for i in low(X)..high(X):
for j in low(Y)..high(Y):
result[i][j] = s[j][i]
let b = [[ 0, 1, 2, 3, 4],
[ 5, 6, 7, 8, 9],
[ 1, 0, 0, 0,42]]
let c = transpose(b)
for r in c:
for i in r:
stdout.write i, " "
echo ""

View file

@ -0,0 +1,11 @@
proc transpose[T](s: seq[seq[T]]): seq[seq[T]] =
result = newSeq[seq[T]](s[0].len)
for i in 0 .. < s[0].len:
result[i] = newSeq[T](s.len)
for j in 0 .. < s.len:
result[i][j] = s[j][i]
let a = @[@[ 0, 1, 2, 3, 4],
@[ 5, 6, 7, 8, 9],
@[ 1, 0, 0, 0,42]]
echo transpose(a)

View file

@ -0,0 +1,9 @@
function transpose(sequence in)
sequence out = repeat(repeat(0,length(in)),length(in[1]))
for n=1 to length(in) do
for m=1 to length(in[1]) do
out[m][n] = in[n][m]
end for
end for
return out
end function

View file

@ -0,0 +1,10 @@
load "stdlib.ring"
transpose = newlist(5,4)
matrix = [[78,19,30,12,36], [49,10,65,42,50], [30,93,24,78,10], [39,68,27,64,29]]
for i = 1 to 5
for j = 1 to 4
transpose[i][j] = matrix[j][i]
see "" + transpose[i][j] + " "
next
see nl
next

View file

@ -0,0 +1,24 @@
(1) -> originalMatrix := matrix [[1, 1, 1, 1],[2, 4, 8, 16], _
[3, 9, 27, 81],[4, 16, 64, 256], _
[5, 25, 125, 625]]
+1 1 1 1 +
| |
|2 4 8 16 |
| |
(1) |3 9 27 81 |
| |
|4 16 64 256|
| |
+5 25 125 625+
Type: Matrix(Integer)
(2) -> transposedMatrix := transpose(originalMatrix)
+1 2 3 4 5 +
| |
|1 4 9 16 25 |
(2) | |
|1 8 27 64 125|
| |
+1 16 81 256 625+
Type: Matrix(Integer)

View file

@ -0,0 +1,15 @@
func transpose(matrix) {
matrix[0].range.map{|i| matrix.map{_[i]}};
};
var m = [
[1, 1, 1, 1],
[2, 4, 8, 16],
[3, 9, 27, 81],
[4, 16, 64, 256],
[5, 25, 125, 625],
];
transpose(m).each { |row|
"%5d" * row.len -> printlnf(row...);
}

View file

@ -0,0 +1,7 @@
function transpose(A) {
return map(range(sizeof A), function(k, idx) {
return map(A, function(k, row) {
return row[idx];
});
});
}

View file

@ -0,0 +1 @@
@zipm [[1 2 3] [4 5 6] [7 8 9]]

View file

@ -0,0 +1,4 @@
def transpose:
if (.[0] | length) == 0 then []
else [map(.[0])] + (map(.[1:]) | transpose)
end ;