This challenge is inspired by a puzzle I played, consisting of foam pieces like these:
which have to be assembled into 3D cubes, like these:
The puzzle pieces can be viewed as grids of 5 * 5 squares, whose middle 3 * 3 squares are always solid, while the 16 squares on the edges can be solid or empty.
A piece will be described using a string of 16 characters (0
s and 1
s), representing the configuration of its edges (0
=empty, 1
=solid), in clockwise order, starting from the top left corner.
For example, the string:
0101001000101101
represents this piece:
# #
####
####
####
# #
In order to fit the pieces together to form the cube, every piece can be rotated in any direction. For example, these are the valid rotations of the piece shown above:
# # # # # ## #
#### #### #### ####
#### #### #### ####
#### #### #### ####
# # # # ## # #
# # # # # ## #
#### #### #### ####
#### #### #### ####
#### #### #### ####
# # # # # # ##
Challenge
Write a program or function that takes as input 6 puzzle pieces and prints or returns a 2D representation of the solved cube.
Input
The input will be a string of 6 rows, where each row consists of 16 0
or 1
characters, representing a piece's edges (in the format described above).
It can be assumed that there is a solution for the input.
The trailing newline is optional.
Output
The result will be an ASCII representation of the solved cube, unfolded in 2D, like this (the diagram uses Rubik's Cube notation for side names):
+---+
|BA |
|CK |
| |
+---+---+---+---+
|LE |DO |RI |UP |
|FT |WN |GHT| |
| | | | |
+---+---+---+---+
|FR |
|ONT|
| |
+---+
To avoid the possibility of presenting the solution in multiple ways, the piece placed DOWN will always be the first piece present in the input, in the same rotation as it is specified there.
Every piece will be represented graphically as a 5 * 5 matrix, using spaces to denote empty squares. For solid squares you can use whatever non-space character you wish, as long as:
- any piece of the puzzle will have its solid squares represented using the same character
- any two adjacent pieces use different characters
Space padding to the right and the trailing newline are optional.
Test Cases
1.
Input:
0010010101010101
0010001011011010
0101001001010010
0010110100101101
0010110110101101
0010001011010101
Output:
@ @
@@@
@@@@@
@@@
** **@#@** *# #
***#####***#####
*****###*****###
***#####***#####
* @#@#** ** # #
@@@@
@@@@
@@@@
@ @
2.
Input:
0001110110101101
1010010111011101
0101010101010010
1010001000100011
1010001001010001
0110010100100010
Output:
@
@@@@
@@@@
@@@@
** **@@## * *# #
****#####****###
****###*****####
****#####***####
** *#@#@# * # #
@@@@
@@@@
@@@@
@ @
3.
Input:
0101001011011010
0010001000100010
0101001011010010
0101010101011010
0101101001011101
1010001001011101
Output:
@ @@
@@@@@
@@@
@@@@@
* * @#@#* * #
*****###*****###
***#####***#####
*****###*****###
* ##@##* * #
@@@@
@@@@
@@@@
@@ @@
This is codegolf, so the shortest program in bytes wins.