Pentomino 6x10 solution normalizer

Clash Royale CLAN TAG#URR8PPP
up vote
5
down vote
favorite
As you most probably now, there are 2339 solutions to pentomino puzzle in a 6x10 grid. There are different labeling schemes for the 12 pentominoes, two of them are shown on the image below:

Image credit: Wikipedia
For the purposes of the current task we will say that a normalized pentomino solution is a solution that uses the second labeling scheme (ConwayâÂÂs).
Example:
O O O O O S S S Z Z
P P R R S S W W Z V
P P P R R W W Z Z V
U U X R T W Y V V V
U X X X T Y Y Y Y Q
U U X T T T Q Q Q Q
The piece with 5 squares in a row is denoted with letters O, according to the scheme. The same is true for all pieces.
Task:
Given a solution to the 6x10 pentomino in which the pieces are labeled with a random sheme, normalize it so that all pieces are labeled in ConwayâÂÂs labeling scheme. You need to recognize the pieces and mark each square of a particular piece with the symbol of the piece.
Input:
The solution to be normalized, in any format that is convenient for you, for example:
A multiline string
A list of strings
A list of lists of characters
and so on
Output:
The same solution (all the pieces positions and orientation preserved), but each piece labeled according to ConwayâÂÂs labeling scheme.
Note: The output MUST be PRINTED as a 6x10 grid of characters. Leading and trailing newlines and spaces are permitted. You can also print a space between the characters (but not empty lines), as in the example above.
Test cases:
1.
Input:
6623338888
6222344478
66A234BB70
1AAA94B770
11A99BB700
1199555550
Output:
UURTTTQQQQ
URRRTVVVSQ
UUXRTVZZSY
PXXXWVZSSY
PPXWWZZSYY
PPWWOOOOOY
2.
Input:
45ookkkk00
455ooogk00
4a55gggdd0
4aaa3gnnd.
4am333ndd.
mmmm3nn...
Output:
OWSSQQQQPP
OWWSSSRQPP
OTWWRRRUUP
OTTTXRZZUV
OTYXXXZUUV
YYYYXZZVVV
Winning criteria:
The shortest solution in bytes in each language wins. DonâÂÂt be discouraged by the golfing languages. Explanations of the algorithms and implementations are welcome.
code-golf pattern-matching pentomino
add a comment |Â
up vote
5
down vote
favorite
As you most probably now, there are 2339 solutions to pentomino puzzle in a 6x10 grid. There are different labeling schemes for the 12 pentominoes, two of them are shown on the image below:

Image credit: Wikipedia
For the purposes of the current task we will say that a normalized pentomino solution is a solution that uses the second labeling scheme (ConwayâÂÂs).
Example:
O O O O O S S S Z Z
P P R R S S W W Z V
P P P R R W W Z Z V
U U X R T W Y V V V
U X X X T Y Y Y Y Q
U U X T T T Q Q Q Q
The piece with 5 squares in a row is denoted with letters O, according to the scheme. The same is true for all pieces.
Task:
Given a solution to the 6x10 pentomino in which the pieces are labeled with a random sheme, normalize it so that all pieces are labeled in ConwayâÂÂs labeling scheme. You need to recognize the pieces and mark each square of a particular piece with the symbol of the piece.
Input:
The solution to be normalized, in any format that is convenient for you, for example:
A multiline string
A list of strings
A list of lists of characters
and so on
Output:
The same solution (all the pieces positions and orientation preserved), but each piece labeled according to ConwayâÂÂs labeling scheme.
Note: The output MUST be PRINTED as a 6x10 grid of characters. Leading and trailing newlines and spaces are permitted. You can also print a space between the characters (but not empty lines), as in the example above.
Test cases:
1.
Input:
6623338888
6222344478
66A234BB70
1AAA94B770
11A99BB700
1199555550
Output:
UURTTTQQQQ
URRRTVVVSQ
UUXRTVZZSY
PXXXWVZSSY
PPXWWZZSYY
PPWWOOOOOY
2.
Input:
45ookkkk00
455ooogk00
4a55gggdd0
4aaa3gnnd.
4am333ndd.
mmmm3nn...
Output:
OWSSQQQQPP
OWWSSSRQPP
OTWWRRRUUP
OTTTXRZZUV
OTYXXXZUUV
YYYYXZZVVV
Winning criteria:
The shortest solution in bytes in each language wins. DonâÂÂt be discouraged by the golfing languages. Explanations of the algorithms and implementations are welcome.
code-golf pattern-matching pentomino
1
Related: Which tetromino is this? and related: Print a Pentomino Rectangle.
â Kevin Cruijssen
2 hours ago
@KevinCruijssen Thank you! (I didn't check for questions related to tetromonoes)
â Galen Ivanov
1 hour ago
add a comment |Â
up vote
5
down vote
favorite
up vote
5
down vote
favorite
As you most probably now, there are 2339 solutions to pentomino puzzle in a 6x10 grid. There are different labeling schemes for the 12 pentominoes, two of them are shown on the image below:

Image credit: Wikipedia
For the purposes of the current task we will say that a normalized pentomino solution is a solution that uses the second labeling scheme (ConwayâÂÂs).
Example:
O O O O O S S S Z Z
P P R R S S W W Z V
P P P R R W W Z Z V
U U X R T W Y V V V
U X X X T Y Y Y Y Q
U U X T T T Q Q Q Q
The piece with 5 squares in a row is denoted with letters O, according to the scheme. The same is true for all pieces.
Task:
Given a solution to the 6x10 pentomino in which the pieces are labeled with a random sheme, normalize it so that all pieces are labeled in ConwayâÂÂs labeling scheme. You need to recognize the pieces and mark each square of a particular piece with the symbol of the piece.
Input:
The solution to be normalized, in any format that is convenient for you, for example:
A multiline string
A list of strings
A list of lists of characters
and so on
Output:
The same solution (all the pieces positions and orientation preserved), but each piece labeled according to ConwayâÂÂs labeling scheme.
Note: The output MUST be PRINTED as a 6x10 grid of characters. Leading and trailing newlines and spaces are permitted. You can also print a space between the characters (but not empty lines), as in the example above.
Test cases:
1.
Input:
6623338888
6222344478
66A234BB70
1AAA94B770
11A99BB700
1199555550
Output:
UURTTTQQQQ
URRRTVVVSQ
UUXRTVZZSY
PXXXWVZSSY
PPXWWZZSYY
PPWWOOOOOY
2.
Input:
45ookkkk00
455ooogk00
4a55gggdd0
4aaa3gnnd.
4am333ndd.
mmmm3nn...
Output:
OWSSQQQQPP
OWWSSSRQPP
OTWWRRRUUP
OTTTXRZZUV
OTYXXXZUUV
YYYYXZZVVV
Winning criteria:
The shortest solution in bytes in each language wins. DonâÂÂt be discouraged by the golfing languages. Explanations of the algorithms and implementations are welcome.
code-golf pattern-matching pentomino
As you most probably now, there are 2339 solutions to pentomino puzzle in a 6x10 grid. There are different labeling schemes for the 12 pentominoes, two of them are shown on the image below:

Image credit: Wikipedia
For the purposes of the current task we will say that a normalized pentomino solution is a solution that uses the second labeling scheme (ConwayâÂÂs).
Example:
O O O O O S S S Z Z
P P R R S S W W Z V
P P P R R W W Z Z V
U U X R T W Y V V V
U X X X T Y Y Y Y Q
U U X T T T Q Q Q Q
The piece with 5 squares in a row is denoted with letters O, according to the scheme. The same is true for all pieces.
Task:
Given a solution to the 6x10 pentomino in which the pieces are labeled with a random sheme, normalize it so that all pieces are labeled in ConwayâÂÂs labeling scheme. You need to recognize the pieces and mark each square of a particular piece with the symbol of the piece.
Input:
The solution to be normalized, in any format that is convenient for you, for example:
A multiline string
A list of strings
A list of lists of characters
and so on
Output:
The same solution (all the pieces positions and orientation preserved), but each piece labeled according to ConwayâÂÂs labeling scheme.
Note: The output MUST be PRINTED as a 6x10 grid of characters. Leading and trailing newlines and spaces are permitted. You can also print a space between the characters (but not empty lines), as in the example above.
Test cases:
1.
Input:
6623338888
6222344478
66A234BB70
1AAA94B770
11A99BB700
1199555550
Output:
UURTTTQQQQ
URRRTVVVSQ
UUXRTVZZSY
PXXXWVZSSY
PPXWWZZSYY
PPWWOOOOOY
2.
Input:
45ookkkk00
455ooogk00
4a55gggdd0
4aaa3gnnd.
4am333ndd.
mmmm3nn...
Output:
OWSSQQQQPP
OWWSSSRQPP
OTWWRRRUUP
OTTTXRZZUV
OTYXXXZUUV
YYYYXZZVVV
Winning criteria:
The shortest solution in bytes in each language wins. DonâÂÂt be discouraged by the golfing languages. Explanations of the algorithms and implementations are welcome.
code-golf pattern-matching pentomino
code-golf pattern-matching pentomino
edited 1 hour ago
asked 3 hours ago
Galen Ivanov
5,1721930
5,1721930
1
Related: Which tetromino is this? and related: Print a Pentomino Rectangle.
â Kevin Cruijssen
2 hours ago
@KevinCruijssen Thank you! (I didn't check for questions related to tetromonoes)
â Galen Ivanov
1 hour ago
add a comment |Â
1
Related: Which tetromino is this? and related: Print a Pentomino Rectangle.
â Kevin Cruijssen
2 hours ago
@KevinCruijssen Thank you! (I didn't check for questions related to tetromonoes)
â Galen Ivanov
1 hour ago
1
1
Related: Which tetromino is this? and related: Print a Pentomino Rectangle.
â Kevin Cruijssen
2 hours ago
Related: Which tetromino is this? and related: Print a Pentomino Rectangle.
â Kevin Cruijssen
2 hours ago
@KevinCruijssen Thank you! (I didn't check for questions related to tetromonoes)
â Galen Ivanov
1 hour ago
@KevinCruijssen Thank you! (I didn't check for questions related to tetromonoes)
â Galen Ivanov
1 hour ago
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
5
down vote
APL (Dyalog Classic), 54 53 50 bytes
â´â´'OXRYTPZQUWSV'[âÂÂ5÷â¨âÂÂâÂÂ,ÃÂ/+â¿âÂÂèâµ=âÂÂâµ]
Try it online!
Compute an invariant for each pentomino in the input: measure (âÂÂx,âÂÂy) from each of its squares to its centre of gravity, take abs(âÂÂx) and abs(âÂÂy), sum the x components and separately the y components, and multiply the two sums. This gives 12 distinct results. Then, find the index of each pentomino's invariant in the sorted collection of all invariants. Replace 0 with 'O', 1 with X, 2 with R, etc.
Thank you for the fast answer and the explanation, +1 from me! I meant the solution to be explicitly printed as a 6x10 grid. I changed the descrition, please update your solution - I'm sorry for the inconvenience.
â Galen Ivanov
1 hour ago
@GalenIvanov but... it is a grid. My tests output "ok" instead of printing the result - maybe that's too confusing?
â ngn
1 hour ago
Yes, I was confused by the tests.
â Galen Ivanov
1 hour ago
3
now they print the result before validating it
â ngn
1 hour ago
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
5
down vote
APL (Dyalog Classic), 54 53 50 bytes
â´â´'OXRYTPZQUWSV'[âÂÂ5÷â¨âÂÂâÂÂ,ÃÂ/+â¿âÂÂèâµ=âÂÂâµ]
Try it online!
Compute an invariant for each pentomino in the input: measure (âÂÂx,âÂÂy) from each of its squares to its centre of gravity, take abs(âÂÂx) and abs(âÂÂy), sum the x components and separately the y components, and multiply the two sums. This gives 12 distinct results. Then, find the index of each pentomino's invariant in the sorted collection of all invariants. Replace 0 with 'O', 1 with X, 2 with R, etc.
Thank you for the fast answer and the explanation, +1 from me! I meant the solution to be explicitly printed as a 6x10 grid. I changed the descrition, please update your solution - I'm sorry for the inconvenience.
â Galen Ivanov
1 hour ago
@GalenIvanov but... it is a grid. My tests output "ok" instead of printing the result - maybe that's too confusing?
â ngn
1 hour ago
Yes, I was confused by the tests.
â Galen Ivanov
1 hour ago
3
now they print the result before validating it
â ngn
1 hour ago
add a comment |Â
up vote
5
down vote
APL (Dyalog Classic), 54 53 50 bytes
â´â´'OXRYTPZQUWSV'[âÂÂ5÷â¨âÂÂâÂÂ,ÃÂ/+â¿âÂÂèâµ=âÂÂâµ]
Try it online!
Compute an invariant for each pentomino in the input: measure (âÂÂx,âÂÂy) from each of its squares to its centre of gravity, take abs(âÂÂx) and abs(âÂÂy), sum the x components and separately the y components, and multiply the two sums. This gives 12 distinct results. Then, find the index of each pentomino's invariant in the sorted collection of all invariants. Replace 0 with 'O', 1 with X, 2 with R, etc.
Thank you for the fast answer and the explanation, +1 from me! I meant the solution to be explicitly printed as a 6x10 grid. I changed the descrition, please update your solution - I'm sorry for the inconvenience.
â Galen Ivanov
1 hour ago
@GalenIvanov but... it is a grid. My tests output "ok" instead of printing the result - maybe that's too confusing?
â ngn
1 hour ago
Yes, I was confused by the tests.
â Galen Ivanov
1 hour ago
3
now they print the result before validating it
â ngn
1 hour ago
add a comment |Â
up vote
5
down vote
up vote
5
down vote
APL (Dyalog Classic), 54 53 50 bytes
â´â´'OXRYTPZQUWSV'[âÂÂ5÷â¨âÂÂâÂÂ,ÃÂ/+â¿âÂÂèâµ=âÂÂâµ]
Try it online!
Compute an invariant for each pentomino in the input: measure (âÂÂx,âÂÂy) from each of its squares to its centre of gravity, take abs(âÂÂx) and abs(âÂÂy), sum the x components and separately the y components, and multiply the two sums. This gives 12 distinct results. Then, find the index of each pentomino's invariant in the sorted collection of all invariants. Replace 0 with 'O', 1 with X, 2 with R, etc.
APL (Dyalog Classic), 54 53 50 bytes
â´â´'OXRYTPZQUWSV'[âÂÂ5÷â¨âÂÂâÂÂ,ÃÂ/+â¿âÂÂèâµ=âÂÂâµ]
Try it online!
Compute an invariant for each pentomino in the input: measure (âÂÂx,âÂÂy) from each of its squares to its centre of gravity, take abs(âÂÂx) and abs(âÂÂy), sum the x components and separately the y components, and multiply the two sums. This gives 12 distinct results. Then, find the index of each pentomino's invariant in the sorted collection of all invariants. Replace 0 with 'O', 1 with X, 2 with R, etc.
edited 26 mins ago
answered 1 hour ago
ngn
6,36812358
6,36812358
Thank you for the fast answer and the explanation, +1 from me! I meant the solution to be explicitly printed as a 6x10 grid. I changed the descrition, please update your solution - I'm sorry for the inconvenience.
â Galen Ivanov
1 hour ago
@GalenIvanov but... it is a grid. My tests output "ok" instead of printing the result - maybe that's too confusing?
â ngn
1 hour ago
Yes, I was confused by the tests.
â Galen Ivanov
1 hour ago
3
now they print the result before validating it
â ngn
1 hour ago
add a comment |Â
Thank you for the fast answer and the explanation, +1 from me! I meant the solution to be explicitly printed as a 6x10 grid. I changed the descrition, please update your solution - I'm sorry for the inconvenience.
â Galen Ivanov
1 hour ago
@GalenIvanov but... it is a grid. My tests output "ok" instead of printing the result - maybe that's too confusing?
â ngn
1 hour ago
Yes, I was confused by the tests.
â Galen Ivanov
1 hour ago
3
now they print the result before validating it
â ngn
1 hour ago
Thank you for the fast answer and the explanation, +1 from me! I meant the solution to be explicitly printed as a 6x10 grid. I changed the descrition, please update your solution - I'm sorry for the inconvenience.
â Galen Ivanov
1 hour ago
Thank you for the fast answer and the explanation, +1 from me! I meant the solution to be explicitly printed as a 6x10 grid. I changed the descrition, please update your solution - I'm sorry for the inconvenience.
â Galen Ivanov
1 hour ago
@GalenIvanov but... it is a grid. My tests output "ok" instead of printing the result - maybe that's too confusing?
â ngn
1 hour ago
@GalenIvanov but... it is a grid. My tests output "ok" instead of printing the result - maybe that's too confusing?
â ngn
1 hour ago
Yes, I was confused by the tests.
â Galen Ivanov
1 hour ago
Yes, I was confused by the tests.
â Galen Ivanov
1 hour ago
3
3
now they print the result before validating it
â ngn
1 hour ago
now they print the result before validating it
â ngn
1 hour ago
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f173905%2fpentomino-6x10-solution-normalizer%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password

1
Related: Which tetromino is this? and related: Print a Pentomino Rectangle.
â Kevin Cruijssen
2 hours ago
@KevinCruijssen Thank you! (I didn't check for questions related to tetromonoes)
â Galen Ivanov
1 hour ago