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 amandel
Row = tuple[int, int, int, int, int]
Grid = tuple[Row, Row, Row, Row, Row]
from itertools import chain
from string import ascii_lowercase as alc
def converter(matrix: Grid) -> str:
return ''.join(x if b==1 else x.upper() for b,x in zip(chain(*matrix),alc) if b)
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: