Problem p01121 - Generation 1

Orig Description

Cube Surface Puzzle
Given a set of six pieces, “Cube Surface Puzzle” is to construct a hollow cube with filled surface.
Pieces of a puzzle is made of a number of small unit cubes laid grid-aligned on a plane.
For a puzzle constructing a cube of its side length n,
unit cubes are on either of the following two areas.
    Core (blue): A square area with its side length n−2.
    Unit cubes fill up this area.
Fringe (red): The area of width 1 unit forming the outer fringe of the core.
     Each unit square in this area may be empty or with a unit cube on it.
Each piece is connected with faces of its unit cubes.
Pieces can be arbitrarily rotated and either side of the pieces can
be inside or outside of the constructed cube.
The unit cubes on the core area should come in the centers of the
faces of the constructed cube.
Consider that we have six pieces in Fig. E-1 (The first dataset of Sample Input).
Then, we can construct a cube as shown in Fig. E-2.
  Fig. E-1 Pieces from the first dataset of Sample Input
  Fig. E-2 Constructing a cube
Mr. Hadrian Hex has collected a number of cube surface puzzles.
One day, those pieces were mixed together and he
cannot find yet from which six pieces he can construct a cube.
Your task is to write a program to help Mr. Hex, which judges whether we can construct a cube for a given set of pieces.
Input
The input consists of at most 200 datasets, each in the following format.
n
x1,1x1,2 … x1,n
x2,1x2,2 … x2,n
…
x6n,1x6n,2 … x6n,n
  The first line contains an integer n denoting the length of one side of the  cube to be constructed (3 ≤ n ≤ 9, n is odd).
The following 6n lines give the six pieces.
Each piece is described in n lines.
Each of the lines corresponds to one grid row and each of the characters in
the line, either ‘X’ or ‘.’, indicates whether or not a unit cube is on
the corresponding unit square: ‘X’ means a unit cube is on the column and ‘.’ means none is there.
  The core area of each piece is centered in the data for the piece.
The end of the input is indicated by a line containing a zero.
Output
  For each dataset, output “Yes” if we can construct a cube, or “No” if we cannot.
Sample Input
5
..XX.
.XXX.
XXXXX
XXXXX
X....
....X
XXXXX
.XXX.
.XXX.
.....
..XXX
XXXX.
.XXXX
.XXXX
...X.
...X.
.XXXX
XXXX.
XXXX.
.X.X.
XXX.X
.XXXX
XXXXX
.XXXX
.XXXX
XX...
.XXXX
XXXXX
XXXXX
XX...
5
..XX.
.XXX.
XXXXX
XXXX.
X....
....X
XXXXX
.XXX.
.XXX.
.....
.XXXX
XXXX.
.XXXX
.XXXX
...X.
...X.
.XXXX
XXXX.
XXXX.
.X.X.
XXX.X
.XXXX
XXXXX
.XXXX
.XXXX
XX...
XXXXX
XXXXX
.XXXX
XX...
0
Output for the Sample Input
Yes
No

Extracted Specification

An integer \( n \) (3 ≤ \( n \) ≤ 9, \( n \) is odd), representing some dimension or length.
A list of 6 * \( n \) strings, each string of length \( n \), containing either 'X' or '.'.

### Example Input:

```
5
..XX.
.XXX.
XXXXX
XXXXX
X....
....X
XXXXX
.XXX.
.XXX.
.....
..XXX
XXXX.
.XXXX
.XXXX
...X.
...X.
.XXXX
XXXX.
XXXX.
.X.X.
XXX.X
.XXXX
XXXXX
.XXXX
.XXXX
XX...
.XXXX
XXXXX
XXXXX
XX...
0
```

### Function Signature:
Write a function `f(n, pieces)` that takes in the input.

```python
def f(n: int, pieces: List[str]):
    '''
    n: an integer
    pieces: a list of strings
    '''
```

Test Case Generator

Certainly! Here's a Python function to generate test cases for the "Cube Surface Puzzle" problem:

```python
import random

def generate_piece(n):
    piece = []
    for _ in range(n):
        row = ''.join(random.choice(['X', '.']) for _ in range(n))
        piece.append(row)
    return piece

def generate_dataset():
    n = random.choice([3, 5, 7, 9])  # n is odd and between 3 and 9
    pieces = []
    for _ in range(6):
        piece = generate_piece(n)
        pieces.append(piece)
    return n, pieces

def tcgen(num_datasets=200):
    datasets = []
    for _ in range(num_datasets):
        n, pieces = generate_dataset()
        datasets.append((n, pieces))
    return datasets

def print_dataset(n, pieces):
    print(n)
    for piece in pieces:
        for row in piece:
            print(row)

# Generate test cases
datasets = tcgen()

# Print the generated test cases in the required format
for dataset in datasets:
    n, pieces = dataset
    print_dataset(n, pieces)
print(0)  # End of input indicator
```

### Explanation:
1. **generate_piece(n)**:
   - Generates a single piece of size `n x n`, where each element is either 'X' or '.'.
   
2. **generate_dataset()**:
   - Randomly selects an odd number `n` between 3 and 9.
   - Generates 6 pieces using the `generate_piece(n)` function.
   
3. **tcgen(num_datasets=200)**:
   - Generates `num_datasets` datasets (default is 200).
   - Each dataset consists of a value `n` and a list of 6 pieces.
   
4. **print_dataset(n, pieces)**:
   - Prints the dataset in the format specified in the problem statement.
   
5. **Printing the generated test cases**:
   - Generate the datasets using `tcgen()`.
   - Iterate through each generated dataset and print them using `print_dataset()`.
   - Finally, print `0` to indicate the end of the input.

When you run this script, it will generate 200 datasets, each with a random configuration of pieces, and print them in the required format. The last line will be `0`, indicating the end of the input.

Extract Arguments

def extract_arguments(fh):
    datasets = []
    while True:
        n = int(fh.readline().strip())
        if n == 0:
            break
        pieces = []
        for _ in range(6 * n):
            pieces.append(fh.readline().strip())
        datasets.append((n, pieces))
    return datasets

# Example usage:
# with open('input.txt', 'r') as fh:
#     datasets = extract_arguments(fh)
#     for n, pieces in datasets:
#         print(n, pieces)