Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Matrix-2-String by Alex_JC
def converter(matrix):
A, R = "abcdefghijklmnopqrstuvwxy", ""
for i, line in enumerate(matrix):
for j, value in enumerate(line):
if value: R += A[i*5+j] if value == 1 else A[i*5+j].upper()
return R
print("Example:")
print(
converter(
(
(0, 0, 1, 0, 0),
(0, 1, 0, 1, 0),
(1, 0, 2, 0, 1),
(0, 1, 0, 1, 0),
(0, 0, 1, 0, 0),
)
)
)
# These "asserts" are used for self-checking
assert (
converter(
(
(0, 0, 1, 0, 0),
(0, 1, 0, 1, 0),
(1, 0, 2, 0, 1),
(0, 1, 0, 1, 0),
(0, 0, 1, 0, 0),
)
)
== "cgikMoqsw"
)
assert (
converter(
(
(1, 0, 1, 0, 1),
(0, 2, 0, 2, 0),
(1, 0, 1, 0, 1),
(0, 2, 0, 2, 0),
(1, 0, 1, 0, 1),
)
)
== "aceGIkmoQSuwy"
)
print("The mission is done! Click 'Check Solution' to earn rewards!")
Feb. 8, 2024
Comments: