Created
April 2, 2019 19:05
-
-
Save molowny/62d744d385ad2f55d6c4fcf58841828e to your computer and use it in GitHub Desktop.
Matrix transpose in Elixir
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
matrix = [[1,2,3,4], [5,6,7,8]] | |
defmodule Matrix do | |
def transpose([[] | _]), do: [] | |
def transpose(m) do | |
[Enum.map(m, &hd/1) | transpose(Enum.map(m, &tl/1))] | |
end | |
end | |
IO.inspect matrix | |
IO.inspect Matrix.transpose(matrix) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment