Pattern Bus
Problem Statement
You are playing the famous BUS game with your friend, where you need to say “BUS” for multiples of 5 instead of saying the number itself. So, the sequence goes:
(1), (2), (3), (4), (BUS) (6), (7), (8), (9), (BUS), …, (N-1), (N)
You need to print this sequence in a slightly different matrix format, whose dimensions are N and M.
Input Format:
- The first line contains one integer, T, the number of test cases.
- Each test case contains two integers N and M on a separate line, denoting the number of rows and columns respectively.
Output Format:
Print the BUS sequence in matrix form with N x M elements.
Constraints:
- 1 ≤ T ≤ 10
- 10 ≤ N, M ≤ 103
Sample Input
Sample Output
Solution
pattern_bus.py
for _ in range(int(input())):
n, m = map(int, input().split())
cnt = 1
for i in range(n):
res = []
for j in range(m):
res.append('(BUS)' if cnt % 5 == 0 else res.append(f'({cnt})'))
cnt += 1
print(' '.join(res))