Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from typing import Any


def list_transpose(list: list[Any]) -> list[Any]:
r = len(list)
c = len(list[0]) if r != 0 else 0
if r == 0 or c == 0:
return []
if any(len(row) != c for row in list):
return []

ret = [[0] * r for _ in range(c)]
for i in range(c):
for j in range(r):
ret[i][j] = list[j][i]
return ret
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": "list_transpose"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from . import *


def test_improper_input() -> None:
assert len(list_transpose([])) == 0
assert len(list_transpose([[], []])) == 0
assert len(list_transpose([[0], [0, 1]])) == 0


def assert_matrices_equal(list1, list2):
assert len(list1) == len(list2)
for i in range(len(list1)):
assert len(list1[i]) == len(list2[i])
for j in range(len(list1[i])):
assert list1[i][j] == list2[i][j]


def test_nonsymetric_transpose() -> None:
input_1 = [[0, 1, 2, 3], [4, 5, 6, 7], [8, 9, 10, 11]]
input_2 = [
["0", "1", "2"],
["3", "4", "5"],
["6", "7", "8"],
["9", "10", "11"],
]
expected_1 = [[0, 4, 8], [1, 5, 9], [2, 6, 10], [3, 7, 11]]
expected_2 = [
["0", "3", "6", "9"],
["1", "4", "7", "10"],
["2", "5", "8", "11"],
]
actual_1 = list_transpose(input_1)
actual_2 = list_transpose(input_2)
assert_matrices_equal(expected_1, actual_1)
assert_matrices_equal(expected_2, actual_2)


def test_symetric_transpose() -> None:
input_1 = [[0, 1, 2], [3, 4, 5], [6, 7, 8]]
expected = [[0, 3, 6], [1, 4, 7], [2, 5, 8]]
actual = list_transpose(input_1)

assert_matrices_equal(expected, actual)
Original file line number Diff line number Diff line change
Expand Up @@ -2587,6 +2587,31 @@ def is_palindrome(sequence: list | str) -> bool:
########################### END ADVENTURE PACK CODE ############################"
`;

exports[`App can equip single goody: Python 3 list_transpose 1`] = `
"########################## BEGIN ADVENTURE PACK CODE ###########################
# Adventure Pack commit fake-commit-hash
# Running at: https://example.com/

from typing import Any


def list_transpose(list: list[Any]) -> list[Any]:
r = len(list)
c = len(list[0]) if r != 0 else 0
if r == 0 or c == 0:
return []
if any(len(row) != c for row in list):
return []

ret = [[0] * r for _ in range(c)]
for i in range(c):
for j in range(r):
ret[i][j] = list[j][i]
return ret

########################### END ADVENTURE PACK CODE ############################"
`;

exports[`App can equip single goody: Python 3 traverse_inorder 1`] = `
"########################## BEGIN ADVENTURE PACK CODE ###########################
# Adventure Pack commit fake-commit-hash
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1459,6 +1459,25 @@ exports[`App can render goody: Python 3 is_palindrome 1`] = `
return True"
`;

exports[`App can render goody: Python 3 list_transpose 1`] = `
"from typing import Any


def list_transpose(list: list[Any]) -> list[Any]:
r = len(list)
c = len(list[0]) if r != 0 else 0
if r == 0 or c == 0:
return []
if any(len(row) != c for row in list):
return []

ret = [[0] * r for _ in range(c)]
for i in range(c):
for j in range(r):
ret[i][j] = list[j][i]
return ret"
`;

exports[`App can render goody: Python 3 traverse_inorder 1`] = `
"from typing import Generator, Optional

Expand Down