Problem p01802 - Generation 2

Orig Description

Problem
Koto City is a famous city with a grid-like road system, as shown in the figure below. Roads extending north-south and east-west are arranged at intervals of 1 km. Assume that Koto Station located at the southwesternmost intersection of Koto City is (0,0), and the position reached by going x km east and y km north from there is expressed as (x,y) (0 ≤ x,y).
In anticipation of an increase in tourists due to the Olympics to be held in five years, the city has decided to build a new subway line starting from Koto Station. Currently, a plan is being made to lay rails from Koto Station to Shin-Koto Station, which will be newly built as the next station from Koto Station. The rails will be laid straight from Koto Station to Shin-Koto Station. Therefore, the length of the rails is √(x2+y2) when the location of Shin-Koto Station is expressed as (x,y). The cost of laying rails is required as much as the length of the rails laid, even if the length of the rails is a decimal such as 1.5 km.
The location (x,y) of Shin-Koto Station has not yet been determined, and it is planned to be located in a place that satisfies the following conditions:
It is an intersection. That is, x and y are integers, respectively.
The shortest distance walked along the road from Koto Station is exactly D, that is, x + y = D.
Among those that satisfy the above two conditions, choose the location of Shin-Koto Station so that the difference between the budget for rails that the city specifies and the cost of the rails |√(x2+y2) - E| is minimized. Here, |A| represents the absolute value of A. Your task is to create a program that outputs the cost difference between the cost of laying the rails and the budget when Shin-Koto Station is built as described above. 
Input
The input is composed of multiple data sets, and the number of data sets included in one input is up to 100. The format of each data set is as follows:
D E
D (1 ≤ D ≤ 100) is an integer representing the shortest distance walked along the road from Koto Station to Shin-Koto Station. E (1 ≤ E ≤ 100) is an integer representing the budget for rail construction.
The end of the input is indicated by a line consisting of two zeros separated by a space.
Output
For each data set, output the difference between the cost of laying the rails when the rails are laid as described above and the budget in one line. There should be no absolute error greater than 10-3. If you do not output a newline at the end of each line or output unnecessary characters, it will be judged as incorrect answer, so be careful.
Sample Input
2 1
7 5
7 6
7 7
76 5
8 41
0 0
Output for Sample Input
0.4142135624
0
0.0827625303
0
48.7401153702
33
Hint
For the first data set, the intersections that are 2 km along the road from Koto Station are expected to be candidates for the location of Shin-Koto Station

Extracted Specification

An integer D (1 ≤ D ≤ 100).
An integer E (1 ≤ E ≤ 100).

The input consists of multiple data sets with up to 100 sets.
The end of the input is indicated by a line consisting of two zeros separated by a space.

### Example Input:

```
2 1
7 5
7 6
7 7
76 5
8 41
0 0
```

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

Test Case Generator

Sure, here is the test case generator for the given problem statement:

```python
import random

def tcgen():
    test_cases = []
    num_tests = random.randint(1, 100)  # Number of datasets in one input (up to 100)
    
    for _ in range(num_tests):
        D = random.randint(1, 100)  # D is an integer representing the shortest distance walked
        E = random.randint(1, 100)  # E is an integer representing the budget for rail construction
        test_cases.append((D, E))
    
    return test_cases

def format_test_cases(test_cases):
    formatted_cases = "\n".join(f"{D} {E}" for D, E in test_cases)
    return f"{formatted_cases}\n0 0"

# Generate test cases
test_cases = tcgen()

# Format the test cases into the required input format
formatted_input = format_test_cases(test_cases)

print(formatted_input)
```

### Explanation:

1. **`tcgen` Function**:
   - This function generates a random number of test cases (between 1 and 100).
   - For each test case, it randomly generates values for `D` and `E` within the specified ranges (1 ≤ D, E ≤ 100).

2. **`format_test_cases` Function**:
   - This function formats the generated test cases into the required input format.
   - It joins all test cases into a single string, each test case on a new line.
   - It appends the termination line `0 0` at the end.

### Usage:

- The `tcgen` function generates the test cases.
- The `format_test_cases` function formats the test cases as required by the problem statement.
- The final formatted input can be printed or used as desired for testing the solution.

This generator ensures that the test cases adhere to the constraints and the required input format for the problem.

Extract Arguments

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