240. Bingo Card Generator
Asked in
Bingo Card Generator
Generate a Bingo card with 3 rows and 9 columns. The card must contain exactly 5 numbers in each row, and all remaining positions must contain 0.
Numbers must follow column ranges. The first column can contain only numbers from 1 to 10, the second column can contain only numbers from 11 to 20, and this pattern continues until the ninth column, which can contain only numbers from 81 to 90.
A generated card must contain exactly 15 positive numbers in total. Positive numbers must be unique across the whole card. Every column must contain at least one positive number. Inside each column, positive numbers must appear in increasing order from top to bottom, ignoring 0 values.
The card must be generated using the deterministic formula given below. No random function should be used. The same seed must always generate the exact same Bingo card.

Method

Generate Card

List<String> generateCard(int seed)
  • Returns a Bingo card generated using the given seed.
  • The returned list must contain exactly 3 strings.
  • Each string represents one row of the card.
  • Each row string must contain exactly 9 comma-separated integers.
  • Use 0 for empty positions.
  • The same seed must always return the exact same card.

Generation Formula

Use the following fixed positive-cell layout.
  • Row 0 has positive numbers in columns 0, 2, 4, 6, and 7.
  • Row 1 has positive numbers in columns 1, 3, 5, 6, and 8.
  • Row 2 has positive numbers in columns 0, 1, 2, 4, and 7.
For each column col, let count be the number of positive cells in that column. Generate the numbers for that column using the formula below.
  • low = col * 10 + 1
  • offset = (seed + 7 * col) % (11 - count)
  • The first number in the column is low + offset.
  • The second number in the column, if needed, is low + offset + 1.
  • The third number in the column, if needed, is low + offset + 2.
  • Place the generated numbers into the positive cells of that column from top to bottom.
  • All other cells must contain 0.

Card Rules

  • The card has exactly 3 rows and exactly 9 columns.
  • Each row contains exactly 5 positive numbers.
  • Each row contains exactly 4 zero values.
  • The card contains exactly 15 positive numbers in total.
  • Every positive number must be unique in the card.
  • Every column must contain at least one positive number.
  • For every column, positive numbers must be sorted in increasing order from top to bottom.

Column Ranges

  • Column 0 can contain only numbers from 1 to 10, both inclusive.
  • Column 1 can contain only numbers from 11 to 20, both inclusive.
  • Column 2 can contain only numbers from 21 to 30, both inclusive.
  • Column 3 can contain only numbers from 31 to 40, both inclusive.
  • Column 4 can contain only numbers from 41 to 50, both inclusive.
  • Column 5 can contain only numbers from 51 to 60, both inclusive.
  • Column 6 can contain only numbers from 61 to 70, both inclusive.
  • Column 7 can contain only numbers from 71 to 80, both inclusive.
  • Column 8 can contain only numbers from 81 to 90, both inclusive.

Constraints

  • 0 ≤ seed ≤ 1,000,000,000
  • The output must contain exactly 3 rows.
  • Each output row must contain exactly 9 comma-separated integers.
  • Empty cells must be represented using 0.
  • No returned row string should contain null values.
  • Returned row strings must not contain spaces before or after commas.

Examples

Example 1

BingoCardGenerator generator = new BingoCardGenerator();
Input: seed = 12
Method call: generator.generateCard(12)
Output:
  • "4,0,29,0,45,0,61,78,0"
  • "0,12,0,34,0,58,62,0,89"
  • "5,13,30,0,46,0,0,79,0"
Explanation: The fixed layout is used. Column numbers are generated using the formula based on seed = 12.

Example 2

BingoCardGenerator generator = new BingoCardGenerator();
Input: seed = 45
Method call: generator.generateCard(45)
Output:
  • "1,0,26,0,42,0,67,75,0"
  • "0,18,0,37,0,51,68,0,82"
  • "2,19,27,0,43,0,0,76,0"
Explanation: The same deterministic formula is applied with seed = 45. Each row has exactly 5 positive numbers and every column has at least one positive number.

Example 3

BingoCardGenerator generator = new BingoCardGenerator();
Input: seed = 45
Method call: generator.generateCard(45)
Output:
  • "1,0,26,0,42,0,67,75,0"
  • "0,18,0,37,0,51,68,0,82"
  • "2,19,27,0,43,0,0,76,0"
Explanation: Calling the method again with the same seed returns the exact same Bingo card.


Please use Laptop/Desktop or any other large screen to add/edit code.