java recursion on array

Posted by user69514 on Stack Overflow See other posts from Stack Overflow or by user69514
Published on 2010-04-22T18:48:58Z Indexed on 2010/04/22 18:53 UTC
Read the original article Hit count: 432

Filed under:
|
|
|

I have to create a program that finds all the possible ways of filling a board of size 3xN You place a domino which takes up 2 spaces to completely fill the board. So far, this is my thought process on how it should be done based on what the teacher has said as well as my own thoughts.

  • Get input and check if its even or odd
  • If it's odd, the board can't be filled all the way and the program ends
  • If it's even, place a domino horizontally in the top right corner of the board
  • Test if you can place a domino vertically in that spot.
  • Repeat those two steps as many times as possible.

The problem is I don't know how to code it to the point where you can remember the placements of each domino. I can get it to where it fills the board completely once and maybe twice, but nothing past that. I also know that I'm supposed to use recursion to figure this out fwiw. Here is the code I started on so far. There is also a main method and I have the initial even/odd check working fine. This is the part I have no idea on.

public void recurDomino(int row, int column) {
        if (Board[2][x - 1] != false) {

        } else if(Board[1][x-1]!=false)
        {

        }
        else {
            for (int n=0; n < x - 1; n++) {
                Board[row][column] = true;
                Board[row][column+1] = true;
                column++;
                counter++;
            } 
            recurDomino(1, 0);
            recurDomino(2, 0);

        }
    }

Thank you for any help you guys can give me.

© Stack Overflow or respective owner

Related posts about homework

Related posts about recursion