Problem p01322 - Generation 1

Orig Description

Problem B: Lottery Checker
You have just finished sorting out your university placement and are in the middle of moving from Komaba to Hongou. As you tidy up your house, you find a large number of lottery tickets that you purchased last year. After checking the exchange deadline, you realize that you must redeem them by tomorrow. However, you have not finished preparing for the move and it would be a hassle to go to the lottery ticket sales office for a small amount of prize money. Therefore, you have decided to investigate how much prize money you can win.
The lottery consists of an 8-digit number. The winning numbers are also 8 digits long and consist of numbers and '*'. If the number portion of the ticket you have matches the number portion of the winning number, you will receive the corresponding prize money. For example, if you have a ticket with the number "12345678", you will win if the winning number is "*******8" or "****5678", but not if the winning number is "****4678". There may be multiple winning numbers, and each winning number will be paid independently. However, a single lottery ticket will not win more than one winning number. For example, if there are two winning numbers, "*******8" and "****5678", the ticket "12345678" will win both, which is not possible. 
Your task is to write a program that, given the lottery ticket number you hold and the winning number of the lottery, will output how much prize money you can win.
Input
The input is given in the following format.
n m
N1 M1
...
Nn Mn
B1
...
Bm
The first line contains two integers: the number of winning numbers n (1 ≤ n ≤ 100) and the number of lottery tickets you have m (1 ≤ m ≤ 1000).
For the next n lines, each line contains a winning number Ni and the prize money Mi (1 ≤ Mi ≤ 1000000). The prize money is an integer. The format of the winning number is as described in the problem statement.
For the next m lines, the lottery ticket numbers that you hold are given. 
Output
Output the total amount of prize money.
Notes on Test Cases
Multiple data sets are given in the input format above. Create a program that outputs in the output format above for each data set.
The end of the input is indicated by n = 0.
Sample Input
3 3
*******1 100
******22 1000
11111112 1000000
01203291
02382022
11111111
10 10
****3228 149416
****3992 198635
****4286 77783
****4843 225244
***49835 231046
***59393 379996
*5763748 437345
*6726222 58054
*8117882 16375
*9244339 537727
77885716
96726222
26971031
66652868
89599648
37772338
64679621
65479161
92959393
57855682
0 0
Output for Sample Input
1200
438050

Extracted Specification

An integer n (1 ≤ n ≤ 100) and an integer m (1 ≤ m ≤ 1000), each representing some quantity or size.
A list of n tuples, each containing a string of 8 characters (where each character is either a digit or '*') and an integer (1 ≤ Mi ≤ 1000000).
A list of m strings, each consisting of 8 digits.

### Example Input:

```
3 3
*******1 100
******22 1000
11111112 1000000
01203291
02382022
11111111
```

### Function Signature:
Write a function f(n, m, winning_numbers_prizes, tickets) that takes in the input.
def f(n: int, m: int, winning_numbers_prizes: List[Tuple[str, int]], tickets: List[str]):
    '''
    n: an integer
    m: an integer
    winning_numbers_prizes: a list of tuples, each containing a string and an integer
    tickets: a list of strings
    '''

Test Case Generator

Sure, I can help you write a test case generator for the "Lottery Checker" problem. Here is the generator function that produces random test cases based on the given problem constraints:

```python
import random
import string

def generate_random_ticket():
    return ''.join(random.choices(string.digits, k=8))

def generate_random_winning_number():
    num_stars = random.randint(0, 8)
    num_digits = 8 - num_stars
    winning_number = ''.join(random.choices(['*'] * num_stars + list(string.digits), k=8))
    return winning_number

def tcgen():
    n = random.randint(1, 100)
    m = random.randint(1, 1000)
    
    winning_numbers = []
    for _ in range(n):
        winning_number = generate_random_winning_number()
        prize_money = random.randint(1, 1000000)
        winning_numbers.append((winning_number, prize_money))
    
    tickets = [generate_random_ticket() for _ in range(m)]
    
    return (n, m, winning_numbers, tickets)

# Example usage
tc = tcgen()
print(tc)
```

This function generates random test cases with the following steps:

1. Randomly determine the number of winning numbers `n` (between 1 and 100).
2. Randomly determine the number of lottery tickets `m` (between 1 and 1000).
3. Generate `n` winning numbers, each of which is a mix of digits and '*' characters. Prize money for each winning number is randomly set between 1 and 1,000,000.
4. Generate `m` lottery ticket numbers, each of which is a sequence of 8 digits.

The output of this function will be a tuple containing:
- The number of winning numbers `n`.
- The number of lottery tickets `m`.
- A list of tuples, where each tuple contains a winning number and its corresponding prize money.
- A list of lottery ticket numbers.

You can then use this generated data to test your lottery checker program.

Extract Arguments

def extract_arguments(fh):
    data_sets = []
    while True:
        n, m = map(int, fh.readline().strip().split())
        if n == 0 and m == 0:
            break
        winning_numbers = []
        for _ in range(n):
            parts = fh.readline().strip().split()
            winning_numbers.append((parts[0], int(parts[1])))
        lottery_tickets = [fh.readline().strip() for _ in range(m)]
        data_sets.append((n, m, winning_numbers, lottery_tickets))
    return data_sets

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