Solved LeetCode program · 386 of 1,000
#0519 · Random Flip Matrix
Original English source
Keep a shared seed of 2026. Keep a shared flipped as an empty list of whole numbers. Keep a shared rows of 2. Keep a shared columns of 3. Keep a shared total of rows times columns. Keep a shared chosen of 0.
For every cell from 0 to total minus 1.
Place 0 into flipped.
To draw. Set seed to seed times 1103515245 plus 12345. Set seed to seed modulo 2147483648. Set chosen to seed modulo total. The position is chosen. If item position of flipped is 1, draw, return. Set item position of flipped to 1.
For every turn from 1 to 4.
Draw. The position is chosen. The row is position divided by columns. The column is position modulo columns. Show row. Show column.
For every cell from 0 to total minus 1.
Set item cell of flipped to 0.
Draw. The position is chosen. The row is position divided by columns. The column is position modulo columns. Show row. Show column.
Expected stdout
1 0 1 1 0 2 0 0 0 1