FRQ 4 2019
Basic FRQ Completed
public LightBoard(int numRows, int numCols) {
lights = new boolean[numRows][numCols];
for (int r = 0; r < numRows; r++) {
for (int c = 0; c < numCols; c++) {
double onoff = Math.random();
lights[r][c] = onoff < 0.4;
}
}
}
public boolean evaluateLight(int row, int col){
int lightsOn = 0;
for (int r = 0; r < lights.length; r++){
if (lights[r][col]){
lightsOn++;
}
}
if (lights[row][col] && lightsOn % 2 == 0){
return false;
}
if (!lights[row][col] && lightsOn % 3 == 0){
return true;
}
return lights[row][col];
}