Problem p02412 - Generation 3

Orig Description

How many ways?
  Write a program that calculates the number of combinations of three different integers that satisfy the following conditions:
You must choose three different integers from 1 to n.
The sum of the three integers is x.
  For example, if n = 5 and x = 9, there are two combinations:
1 + 3 + 5 = 9
2 + 3 + 4 = 9
Input
  The input consists of multiple datasets. For each dataset, two integers n and x are given on one line.
  The input is terminated by two zeros (n and x). Do not process the program for these end symbols.
Constraints
3 ≤ n ≤ 100
0 ≤ x ≤ 300
Output
  For each dataset, output the number of combinations on one line.
Sample Input
5 9
0 0
Sample Output
2
Note
      Commentary      

Extracted Specification

An integer n (3 ≤ n ≤ 100), representing some quantity or size.
An integer x (0 ≤ x ≤ 300), representing some value.

### Example Input:
```
5 9
0 0
```

### Function Signature:
Write a function f(inputs) that takes in the input.
```python
def f(inputs: List[Tuple[int, int]]):
    ''' 
    inputs: a list of tuples, where each tuple contains two integers
    '''
```

Test Case Generator

Sure, let's create a test case generator for the given problem statement. The generator will produce multiple datasets of integers \( n \) and \( x \) until it hits the termination set of (0, 0).

Here's how you can create the test case generator:

```python
import random

def tcgen():
    test_cases = []

    while True:
        n = random.randint(3, 100)
        x = random.randint(0, 300)

        # Append the generated test case to the list
        test_cases.append((n, x))

        # Randomly decide to add the termination case
        if random.random() < 0.1:  # 10% chance to terminate
            test_cases.append((0, 0))
            break

    return test_cases

# Generate a sample test case list
sample_test_cases = tcgen()
for n, x in sample_test_cases:
    print(n, x)
```

### Explanation:
1. **Initialization**: We start by creating an empty list `test_cases` to store the generated test cases.
2. **Random Generation**:
   - Generate a random integer `n` within the range \([3, 100]\).
   - Generate a random integer `x` within the range \([0, 300]\).
   - Append the generated pair `(n, x)` to the `test_cases` list.
3. **Termination Condition**:
   - Using `random.random() < 0.1`, we give a 10% chance to append the termination case `(0, 0)` and break out of the loop.
4. **Return**: Finally, return the list of test cases.

This generator ensures a variety of test cases with different values of \( n \) and \( x \), and it randomly decides when to stop generating more cases by adding the termination set `(0, 0)`.

Extract Arguments

def extract_arguments(fh):
    inputs = []
    while True:
        line = fh.readline().strip()
        if line == "0 0":
            break
        n, x = map(int, line.split())
        inputs.append((n, x))
    return inputs