A sequel to What dice do I need to display every integer up to X?
Numbers are great, but let's take it to the next level. I'd like to have a set of dice that can be arranged and rotated to display any words I want. Think Boggle:
And not just that; I want to specify the number of sides those dice have. The set should contain the fewest number of dice possible.
For example—
If I want to be able to display any of the following words with 4-sided dice:
CODE
GOLF
IS
VERY
FUN
I would need 4 dice with the following letters on their sides (each line represents a die):
C G I V
O S R U
D L N Y
E F
Note that the last die only has letters on two of its sides.
The challenge:
- Given a number of sides N, and 1 or more words, write a program that outputs the N-sided dice that are required to be able to display all of the words (one at a time).
- The first input is always an integer, 4 at minimum. This number determines the number of sides that each of the dice will have.
- All other inputs are strings of English-alphabet capital letters, at least 1 character in length. They may be provided in any format you like; delimited, a list, array, etc.
- Each side of a die must be either blank or contain a single English-alphabet capital letter.
- Unlike the number challenge, you do not need to ensure that every die is used for every word. If there's a two-letter word and 4 total dice required, you only need to ensure that 2 dice have the correct letters on them.
- Output must be provided so that all the letters on each die is shown, and each die is separated somehow. So
CGIVOSRUDLNYEF
is not valid output for the above example, but these are valid:
CGIV OSRU DLNY EF
CGIV
OSRU
DLNY
EF
["CGIV", "OSRU", "DLNY", "EF"]
[["C", "G", "I", "V"], ["O", "S", "R", "U"], ["D", "L", "N", "Y"], ["E", "F"]]
- The dice in the output, and the letters in each side do not need to be in any particular order.
- A correct solution outputs the fewest possible dice given the inputs.
- There may be multiple correct outputs for a given input. You need only output one.
Here are a couple more test cases:
Input: 4,EASY,TEST,TEASE
Output:
E
A T
S
Y T
E
Input: 5,MEDIC,FROG,WOW,ZEBRA,SCENES,ZOOM,BABOON,LOITER,XRAY,MEDIUM,GUEST,SUNDAY,ROMP
Output:
M S B L G
Z A F W E
D E B T M
M Y S O R
I N W X P
U C O A Y
Bonus challenges:
- Your program must also handle the number of sides being 3, 2, or 1.
- Your program must assume that an
M
can be rotated and used as aW
.W
can never appear in the output. This also goes forC
andU
,Z
andN
,H
andI
. - A correct solution outputs the fewest possible letters for a given input, not just the fewest dice.