Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Cistercian Converter II: Cistercian To Integer by freeman_lex
def cistercian(image: list[list[int]]) -> int:
Coord = tuple[int, int]
Figure = tuple[Coord, Coord, Coord, Coord, Coord, Coord]
Digit = tuple[int, int, int, int, int, int]
ones: Figure = (0, 3), (0, 4), (1, 3), (1, 4), (2, 3), (2, 4)
tens: Figure = (0, 1), (0, 0), (1, 1), (1, 0), (2, 1), (2, 0)
hund: Figure = (6, 3), (6, 4), (5, 3), (5, 4), (4, 3), (4, 4)
thou: Figure = (6, 1), (6, 0), (5, 1), (5, 0), (4, 1), (4, 0)
numb = ones, tens, hund, thou
digits: list[Digit] = [
(0, 0, 0, 0, 0, 0),
(1, 1, 0, 0, 0, 0),
(0, 0, 0, 0, 1, 1),
(0, 0, 1, 0, 0, 1),
(0, 1, 1, 0, 0, 0),
(1, 1, 1, 0, 0, 0),
(0, 1, 0, 1, 0, 1),
(1, 1, 0, 1, 0, 1),
(0, 1, 0, 1, 1, 1),
(1, 1, 0, 1, 1, 1)
]
def getter(coords: Figure) -> int:
digit = tuple(image[r][c]=="0" for r, c in coords)
return digits.index(digit)
res = sum(getter(fig)*pow(10, p) for p, fig in enumerate(numb))
return res
print("Example:")
print(
cistercian(
[
[" ", " ", "0", " ", "0"],
[" ", "0", "0", "0", " "],
["0", " ", "0", " ", " "],
[" ", " ", "0", " ", " "],
[" ", " ", "0", "0", "0"],
[" ", " ", "0", " ", " "],
["0", "0", "0", " ", " "],
]
)
)
# These "asserts" are used for self-checking
assert (
cistercian(
[
[" ", " ", "0", " ", "0"],
[" ", " ", "0", "0", " "],
[" ", " ", "0", " ", " "],
[" ", " ", "0", " ", " "],
[" ", " ", "0", " ", " "],
[" ", " ", "0", " ", " "],
[" ", " ", "0", " ", " "],
]
)
== 4
)
assert (
cistercian(
[
["0", "0", "0", " ", " "],
[" ", "0", "0", " ", " "],
[" ", " ", "0", " ", " "],
[" ", " ", "0", " ", " "],
[" ", " ", "0", " ", " "],
[" ", " ", "0", " ", " "],
[" ", " ", "0", " ", " "],
]
)
== 50
)
assert (
cistercian(
[
[" ", " ", "0", " ", " "],
[" ", " ", "0", " ", " "],
[" ", " ", "0", " ", " "],
[" ", " ", "0", " ", " "],
[" ", " ", "0", " ", "0"],
[" ", " ", "0", " ", "0"],
[" ", " ", "0", " ", "0"],
]
)
== 600
)
assert (
cistercian(
[
[" ", " ", "0", " ", " "],
[" ", " ", "0", " ", " "],
[" ", " ", "0", " ", " "],
[" ", " ", "0", " ", " "],
["0", " ", "0", " ", " "],
["0", " ", "0", " ", " "],
["0", "0", "0", " ", " "],
]
)
== 7000
)
assert (
cistercian(
[
["0", "0", "0", " ", " "],
["0", " ", "0", "0", " "],
["0", "0", "0", " ", "0"],
[" ", " ", "0", " ", " "],
[" ", " ", "0", "0", "0"],
[" ", " ", "0", " ", "0"],
["0", "0", "0", "0", "0"],
]
)
== 1993
)
print("The mission is done! Click 'Check Solution' to earn rewards!")
March 25, 2025
Comments: