Problem p01258 - Generation 2

Orig Description

Problem I: Memory Match
Memory match is a single-player game which employs a set of 2M cards. Each card is labeled with a
number between 1 and M on its face. For each number i (1 ≤ i ≤ M), there are exactly two cards which
have the number i. At the start of the game, all cards are shuffled and laid face down on a table. In each
turn you choose two cards and turn them face up. If two numbers on the cards are the same, they are
removed from the table. Otherwise, they are turned face down again (this is called a mismatch). When
you choose cards, you do not have to turn two cards simultaneously; you can choose the second card
after you see the number of the first card. The objective of the game is to remove all the cards with as
few mismatches as possible.
Royce A. Mitchell has extraordinary memory, so he can remember all the positions and the numbers of
the cards that he has already turned face up. Your task is to write a program that calculates the expected
number of mismatches, on average, when he plays the game optimally.
Input
The input consists of multiple datasets.
Each dataset consists of one even number N (2 ≤ N ≤ 1000) which denotes the number of cards in the
set.
The end of input is indicated by a line that contains a single zero. This is not part of the input and you
may not treat this line as a dataset.
Output
For each dataset, print the expected number of mismatches. Each output value may have an arbitrary
number of fractional digits, provided that the error is within 10-6.
Sample Input
2
4
6
8
10
52
0
Output for the Sample Input
0.0000000000
0.6666666667
1.3333333333
1.9238095238
2.5523809524
15.4435236099

Extracted Specification

An even integer \(N\) (2 ≤ \(N\) ≤ 1000).

The input ends with a single zero which should not be processed.

### Example Input:
```
2
4
6
8
10
52
0
```

### Function Signature:
Write a function f(inputs) that takes in a list of tuples, each containing an even integer \(N\).
```python
def f(inputs: List[int]):
    '''
    inputs: a list of even integers
    '''
```

Test Case Generator

To create a test case generator for the problem "Memory Match", we need to generate multiple datasets, each consisting of an even number \( N \) (where \( 2 \leq N \leq 1000 \)). The end of input is indicated by a line containing a single zero. Here is the Python code for generating such test cases:

```python
import random

def tcgen(num_datasets=10):
    datasets = []
    for _ in range(num_datasets):
        N = random.choice(range(2, 1001, 2))  # Choose an even number between 2 and 1000
        datasets.append(N)
    datasets.append(0)  # Add the end of input indicator
    
    return datasets

# Example usage:
if __name__ == "__main__":
    test_cases = tcgen()
    for case in test_cases:
        print(case)
```

### Explanation:
- The `tcgen` function generates a specified number of datasets (default is 10).
- For each dataset, it randomly selects an even number \( N \) between 2 and 1000.
- It adds these numbers to a list named `datasets`.
- Finally, the function appends a zero to the list, which marks the end of input.

When executed, this function generates a series of test cases, each consisting of an even number \( N \), followed by a zero to indicate the end of input. This matches the format specified in the problem statement.

### Example Output:
The output of the above test case generator might look like this:
```
8
2
1000
14
6
10
52
4
12
18
0
```
Each number represents a dataset, and the zero at the end indicates the end of input.

Extract Arguments

def extract_arguments(fh):
    inputs = []
    while True:
        N = int(fh.readline().strip())
        if N == 0:
            break
        inputs.append((N,))
    return inputs