Orig Description
FizzBuzz
There is a game that uses numbers called "Fizz Buzz". This game is played by multiple players who count up numbers from 1 in turn, and each player says only one number that the previous player said. At that time, if it is divisible by 3, say "Fizz", if it is divisible by 5, say "Buzz", and if it is divisible by both, say "FizzBuzz" instead of the number. For example, the first 16 statements are as follows.
1, 2, Fizz, 4, Buzz, Fizz, 7, 8, Fizz, Buzz, 11, Fizz, 13, 14, FizzBuzz, 16, ...
Taro decided to play "Fizz Buzz" with his friends. Taro and his friends decided on the following rule.
"The person who made a mistake drops out. The next person starts from the number after the wrong number. That is, if you say 1, 2, 3, you made a mistake with 3, so you start with 4 next."
They play the game according to this rule, but because they are not used to the game, they may not notice their mistakes and cannot make a fair judgment. So you decided to create a program that outputs the remaining players at the end of the designated number of statements so that Taro and his friends can enjoy this game.
Create a program that takes the number of players and the number of statements made during the game as input, and outputs the number of remaining players in order of smallest to largest number. However, each player is assigned a number from 1, and statements are made starting from the first player in order, and when all statements are finished, the first player will speak again. If the player whose turn it is has already dropped out, the next player will speak. Also, this program must ignore any statements made after a single player remains.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by two zeros.
Each dataset is given in the following format.
m n
s1
s2
:
sn
The first line gives the number of players m (2 ≤ m ≤ 1000) and the number of statements n (1 ≤ n ≤ 10000).
The following n lines give the i-th statement s1. si is an integer, Fizz, Buzz, or FizzBuzz, a string indicating them (up to 8 characters).
There are no more than 50 datasets in the input.
Output
For each dataset, output the numbers of the remaining players in order from smallest to largest after the specified number of statements has been input.
Sample Input
5 7
1
2
Fizz
4
Buzz
6
7
3 5
1
2
3
4
5
0 0
Output for the Sample Input
2 3 4 5
1
Extracted Specification
An integer m (2 ≤ m ≤ 1000), representing some quantity.
An integer n (1 ≤ n ≤ 10000), representing some quantity.
A list of n statements, each statement being an integer or a string from the set {'Fizz', 'Buzz', 'FizzBuzz'}.
### Example Input:
```
5 7
1
2
Fizz
4
Buzz
6
7
```
### Function Signature:
Write a function f(m, n, statements) that takes in the inputs.
```python
def f(m: int, n: int, statements: List[Union[int, str]]):
'''
m: an integer
n: an integer
statements: a list of integers and strings
'''
```
Test Case Generator
Certainly! Below is a test case generator for the FizzBuzz problem as described in the problem statement. This generator will create random test cases within the constraints provided.
```python
import random
def generate_fizzbuzz_statement(i):
if i % 3 == 0 and i % 5 == 0:
return "FizzBuzz"
elif i % 3 == 0:
return "Fizz"
elif i % 5 == 0:
return "Buzz"
else:
return str(i)
def tcgen():
datasets = []
while len(datasets) < 50: # Generating up to 50 datasets
m = random.randint(2, 1000) # Number of players (2 ≤ m ≤ 1000)
n = random.randint(1, 10000) # Number of statements (1 ≤ n ≤ 10000)
statements = []
for i in range(1, n + 1):
correct_statement = generate_fizzbuzz_statement(i)
if random.random() < 0.1: # 10% chance to introduce an error
options = ["Fizz", "Buzz", "FizzBuzz"]
if correct_statement in options:
options.remove(correct_statement)
statements.append(random.choice(options + [str(i)]))
else:
statements.append(correct_statement)
datasets.append((m, n, statements))
return datasets
def format_test_case(datasets):
formatted_data = []
for m, n, statements in datasets:
formatted_data.append(f"{m} {n}")
formatted_data.extend(statements)
formatted_data.append("0 0")
return "\n".join(formatted_data)
if __name__ == "__main__":
datasets = tcgen()
formatted_test_cases = format_test_case(datasets)
print(formatted_test_cases)
```
### Explanation
1. **Helper Function `generate_fizzbuzz_statement`:**
- This function generates the correct FizzBuzz statement for a given number `i`.
2. **Test Case Generator `tcgen`:**
- Generates up to 50 datasets.
- For each dataset:
- Randomly selects the number of players `m` between 2 and 1000.
- Randomly selects the number of statements `n` between 1 and 10000.
- Generates the correct FizzBuzz sequence for numbers from 1 to `n`.
- Introduces a 10% chance to introduce an incorrect statement.
- Collects all the datasets in a list.
3. **Test Case Formatter `format_test_case`:**
- Converts the list of datasets into a formatted string suitable for input to the FizzBuzz problem.
- Ensures the input ends with `0 0` to indicate the end of the input.
4. **Main Block:**
- Calls the test case generator and formatter, then prints the formatted test cases.
This script will produce randomized test cases within the problem constraints, making it suitable for thorough testing of a solution to the FizzBuzz problem.
Extract Arguments
def extract_arguments(fh):
datasets = []
while True:
m, n = map(int, fh.readline().strip().split())
if m == 0 and n == 0:
break
statements = [fh.readline().strip() for _ in range(n)]
datasets.append((m, n, statements))
return datasets
# if __name__ == "__main__":
# input_path = sys.argv[1]
# with open(input_path, 'r') as fh:
# datasets = extract_arguments(fh)
# for dataset in datasets:
# f(*dataset)