Jump to content

Matrix transposition: Difference between revisions

Updated to work with Nim 1.4: suppressed ".. <".
m (Source and output ormatting.)
(Updated to work with Nim 1.4: suppressed ".. <".)
Line 2,595:
<lang nim>proc transpose[T](s: seq[seq[T]]): seq[seq[T]] =
result = newSeq[seq[T]](s[0].len)
for i in 0 .. < s[0].lenhigh:
result[i] = newSeq[T](s.len)
for j in 0 .. < s.lenhigh:
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)</lang>
{{out}}
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.