Problem p00222 - Generation 1

Orig Description

Quadruplet Primes
  A set of four prime numbers arranged in the form (a, a+2, a+6, a+8) is called a quadruplet prime. Among the four prime numbers that make up the quadruplet prime, the largest number is called the size of the quadruplet prime. For example, the smallest quadruplet prime of size 13 is the set (5, 7, 11, 13), and the next largest quadruplet prime of size 19 is the set (11, 13, 17, 19).
  Write a program that takes an integer n (13 ≤ n ≤ 10,000,000) as input and outputs the size of the largest quadruplet prime whose size is less than or equal to n.
Input
  The input consists of multiple datasets. The end of input is indicated by a line containing a single zero.
For each dataset, a single integer n is given on a line.
  The number of datasets is no more than 2000.
Output
  For each input dataset, output the size of the largest quadruplet prime on a single line.
Sample Input
13
14
15
16
17
18
19
20
10000
0
Output for the Sample Input
13
13
13
13
13
13
19
19
9439

Extracted Specification

An integer T (1 ≤ T ≤ 2000), representing the number of datasets.
A list of integers, each integer n (13 ≤ n ≤ 10,000,000) ending with a zero.

### Example Input:

```
13
14
15
16
17
18
19
20
10000
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

Generating test cases for a problem like "Quadruplet Primes" involves simulating multiple datasets with varying values of \( n \), including edge cases and random cases within the specified range. The generator will need to handle multiple datasets and ensure that the end of input is indicated correctly.

Here is a test case generator for the "Quadruplet Primes" problem:

```python
import random

def is_prime(num):
    """ Helper function to check if a number is prime. """
    if num <= 1:
        return False
    if num <= 3:
        return True
    if num % 2 == 0 or num % 3 == 0:
        return False
    i = 5
    while i * i <= num:
        if num % i == 0 or num % (i + 2) == 0:
            return False
        i += 6
    return True

def find_quadruplet_primes(n):
    """ Find all quadruplet primes up to n. Returns a list of sizes of quadruplet primes. """
    quadruplet_primes = []
    for a in range(2, n - 7):
        if is_prime(a) and is_prime(a + 2) and is_prime(a + 6) and is_prime(a + 8):
            quadruplet_primes.append(a + 8)
    return quadruplet_primes

def tcgen():
    """ Test case generator for the Quadruplet Primes problem. """
    num_datasets = random.randint(1, 2000)
    test_cases = []
    
    for _ in range(num_datasets):
        n = random.randint(13, 10000000)
        test_cases.append(n)
    
    # Ensure we include edge cases
    test_cases += [13, 10000000, 0]
    
    return test_cases

# Generate test cases
test_cases = tcgen()

# Print the test cases in the needed format
for case in test_cases:
    print(case)
```

Explanation:
1. **Prime Checking Function**: `is_prime` is a helper function used to determine if a number is prime.
2. **Quadruplet Primes Finder**: `find_quadruplet_primes` function is used to find all quadruplet primes up to a given number \( n \).
3. **Test Case Generation (`tcgen`)**:
   - Generates a random number of datasets (between 1 and 2000).
   - For each dataset, a random number \( n \) is selected within the given range (13 to 10,000,000).
   - Edge cases are explicitly added (like the smallest and largest possible \( n \), and the termination input `0`).

**Note**: For competitive programming problems, it's crucial to include edge cases to ensure the robustness of the solution. This generator focuses on producing varied and comprehensive test cases, including edge cases and random valid inputs.

Extract Arguments

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

# if __name__ == "__main__":
#     input_path = sys.argv[1]
#     with open(input_path, 'r') as fh: 
#     inputs = extract_arguments(fh)
#     f(inputs)