Pentomino 6x10 solution normalizer

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
5
down vote

favorite
1












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:



enter image description here



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.










share|improve this question



















  • 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














up vote
5
down vote

favorite
1












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:



enter image description here



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.










share|improve this question



















  • 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












up vote
5
down vote

favorite
1









up vote
5
down vote

favorite
1






1





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:



enter image description here



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.










share|improve this question















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:



enter image description here



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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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












  • 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










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.






share|improve this answer






















  • 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










Your Answer




StackExchange.ifUsing("editor", function ()
return StackExchange.using("mathjaxEditing", function ()
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
);
);
, "mathjax-editing");

StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "200"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















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






























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.






share|improve this answer






















  • 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














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.






share|improve this answer






















  • 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












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.






share|improve this answer















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.







share|improve this answer














share|improve this answer



share|improve this answer








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
















  • 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

















 

draft saved


draft discarded















































 


draft saved


draft discarded














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













































































Comments