import java.util.Scanner;

public class TrominoTiling {

    private static String[][] board; // Use a String matrix to store the tiling representation

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("Please enter size of board (need to be 2^n and 0 to quit):");
        int boardSize = scanner.nextInt();

        if(boardSize == 0) {
            System.out.println("Quitting…");
            return;
        }

        if((boardSize & (boardSize - 1)) != 0) {
            System.out.println("Invalid board size. The size must be a power of 2.");
            return;
        }
        
        board = new String[boardSize][boardSize]; // Initialize the board with nulls

        System.out.println("Please enter coordinates of missing square (separated by a space):");
        int x_missing = scanner.nextInt();
        int y_missing = scanner.nextInt();

        // Fill the entire board with placeholders for visualization purposes
        fillBoard(0, 0, boardSize, x_missing, y_missing);

        // Print the final board configuration
        for (int i = 0; i < boardSize; i++) {
            for (int j = 0; j < boardSize; j++) {
                System.out.print(board[i][j] + "\t");
            }
            System.out.println();
        }
    }

    private static void fillBoard(int x, int y, int size, int x_missing, int y_missing) {
        if (size == 1) {
            // Base case, 1x1, this happens after subdividing; nothing to place.
            return;
        }

        if (size == 2) {
            // Base case, manually fill a 2x2 area.
            fill2x2Block(x, y, x_missing, y_missing);
            return;
        }

        int halfSize = size / 2;
        int newX = x_missing < x + halfSize ? x : x + halfSize;
        int newY = y_missing < y + halfSize ? y : y + halfSize;

        // Placeholder tromino for larger subdivisions
        fillBoard(x, y, halfSize, newX, newY);
        fillBoard(x, y + halfSize, halfSize, newX, newY);
        fillBoard(x + halfSize, y, halfSize, newX, newY);
        fillBoard(x + halfSize, y + halfSize, halfSize, newX, newY);
    }

    private static void fill2x2Block(int x, int y, int x_missing, int y_missing) {
        // Place the "MS" and the L-tromino in the correct positions
        for (int i = 0; i < 2; i++) {
            for (int j = 0; j < 2; j++) {
                if (x + i == x_missing && y + j == y_missing) {
                    board[y + j][x + i] = "MS"; // Mark the missing square
                } else if (y + j < y_missing) {
                    if (x + i < x_missing) board[y + j][x + i] = "LL";
                    else board[y + j][x + i] = "LR";
                } else {
                    if (x + i < x_missing) board[y + j][x + i] = "UL";
                    else board[y + j][x + i] = "UR";
                }
            }
        }
    }
}
 the above program is till giving the wrong outputs Please enter size of board (need to be 2^n and 0 to quit):
2
Please enter coordinates of missing square (separated by a space):
0 0
MS UR
UR UR
PS C:\Users\apoor\Downloads\kadam_a_p2> c:; cd ‘c:\Users\apoor\Downloads\kadam_a_p2’; & ‘C:\Program Files\Java\jdk-21\bin\java.exe’ ‘-agentlib:jdwp=transport=dt_socket,server=n,suspend=y,address=localhost:59076’ ‘–enable-preview’ ‘-XX:+ShowCodeDetailsInExceptionMessages’ ‘-cp’ ‘C:\Users\apoor\AppData\Roaming\Code\User\workspaceStorage\a73389fa9c812e0894be36830c879eef\redhat.java\jdt_ws\kadam_a_p2_177a4694\bin’ ‘TrominoTiling’
Please enter size of board (need to be 2^n and 0 to quit):
4
Please enter coordinates of missing square (separated by a space):
1 3
LR LR LR LR
LR LR LR LR
MS UR UR UR
UR UR UR UR . the correct output is Please enter size of board (need to be 2^n and 0 to quit): 2
Please enter coordinates of missing square (seperated by a space): 0 0
UR UR
MS UR
Please enter size of board (need to be 2^n and 0 to quit): 4
Please enter coordinates of missing square (seperated by a space): 1 3
LL MS UR UR
LL LL LR UR
LL LR LR LR
LL LL LR LR I want exactly the same output. make the changes accordingly