1
exercism fetch elixir transpose

Transpose

Given an input text output it transposed.

Roughly explained, the transpose of a matrix:

1
2
ABC
DEF

is given by:

1
2
3
AD
BE
CF

Rows become columns and columns become rows. See https://en.wikipedia.org/wiki/Transpose.

If the input has rows of different lengths, this is to be solved as follows:

Therefore, transposing this matrix:

1
2
ABC
DE

results in:

1
2
3
AD
BE
C

And transposing:

1
2
AB
DEF

results in:

1
2
3
AD
BE
 F

In general, all characters from the input should also be present in the transposed output. That means that if a column in the input text contains only spaces on its bottom-most row(s), the corresponding output row should contain the spaces in its right-most column(s).

Running tests

Execute the tests with:

1
$ elixir transpose_test.exs

Pending tests

In the test suites, all but the first test have been skipped.

Once you get a test passing, you can unskip the next one by commenting out the relevant @tag :pending with a # symbol.

For example:

1
2
3
4
5
6
7
8
9
# @tag :pending
test "two characters in a row" do
  input= "AB"
  expected =
    "A\n" <>
    "B"

  assert Transpose.transpose(input) == expected
end

Or, you can enable all the tests by commenting out the ExUnit.configure line in the test suite.

1
# ExUnit.configure exclude: :pending, trace: true

For more detailed information about the Elixir track, please see the help page.

Submitting Incomplete Solutions

It's possible to submit an incomplete solution so you can see how others have completed the exercise.