Skip to content

Instantly share code, notes, and snippets.

@molowny
Created April 2, 2019 19:05
Show Gist options
  • Save molowny/62d744d385ad2f55d6c4fcf58841828e to your computer and use it in GitHub Desktop.
Save molowny/62d744d385ad2f55d6c4fcf58841828e to your computer and use it in GitHub Desktop.
Matrix transpose in Elixir
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