Problem p01258 - Generation 1

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), representing some quantity or size.
Multiple datasets, each consisting of one even integer \(N\).

The end of input is indicated by a line that contains a single zero.

### Example Input:

```
2
4
6
0
```

### Function Signature:
Write a function f(inputs) that takes in the input.
```python
def f(inputs: List[int]):
    '''
    inputs: a list of integers
    '''
```

Test Case Generator

Certainly! Here is a test case generator for the provided "Memory Match" problem statement:

```python
import random

def tcgen():
    datasets = []
    while True:
        N = random.choice([2, 4, 6, 8, 10] + [i for i in range(12, 1001, 2)])
        if N == 0:
            break
        datasets.append(N)
    datasets.append(0)  # End of input indicator
    return datasets

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

This generator creates multiple datasets by picking an even number \( N \) (ranging from 2 to 1000) randomly. It continues generating datasets until it generates a zero, which indicates the end of the input. This zero is appended at the end of the list of datasets to mark the termination of the input as per the problem statement.

You can run the generator to produce test cases for the problem. The output will be a series of even numbers followed by a `0`, ensuring that the test cases are valid as per the problem's constraints.

Extract Arguments

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