Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 1 of 1

Thread: Texas UIL Problem: 2007

  1. #1
    Member Staticity's Avatar
    Join Date
    Jul 2011
    Location
    Texas
    Posts
    105
    My Mood
    Inspired
    Thanks
    3
    Thanked 5 Times in 5 Posts

    Lightbulb Texas UIL Problem: 2007

    So, in order to practice for future Competitions... I've printed out a few old UIL packets to go through. I noticed a few re-occurring problems that are somewhat difficult, but manageable. I find myself allotting too much time on these couple of problems instead of working on others...

    There's quite a bit, so I understand if you're not willing to read through it all.. Any advice is greatly appreciated though!

    To get to the point, here's what I'd like some advice on:
    - Translating an Array
    ~ For Example, simulate a tetris game through a matrix of characters.. If the bottom row is filled, return a new array that has deleted the bottom row and set the remaining characters on the bottom row.

    My Code:

    public static char[][] removeBottom(char[][] matrix){
          char[][] newArray = new char[matrix.length][matrix.length];
          for(int row = 0; row < matrix.length; row++)
              for(int col = 0; col < matrix.length; col++)
                   newArray[row][col] = '.';
     
          for(int row = 1; row < matrix.length; row++)
              for(int col = 0; col < matrix.length; col++)
                   newArray[row][col] = matrix[i-1][j];
     
          return newArray;
    }

    - Secondly, I come across Mazes
    ~ Here are some questions I come across.. Solve for the shortest path, only path, shortest path length.

    My Code:

    /*
    The following method only removes Dead Ends.
    Only can return shortest path when there is EXACTLY one path
     
    I will only show one method, but if this method returns true.. Another will fill in the Dead End.
    */
    public static boolean containsDeadEnds(char[][] maze){
        for(int row = 0; row < maze.length; row++){
            for(int col = 0; col < maze[row].length; col++){
                 int deadEnds = 0;
                 if(maze[i][j] == '.'){
                    if(maze[i-1][j] == '#')
                       deadEnds++;        
                    if(maze[i+1][j] == '#')
                       deadEnds++;
                    if(maze[i][j-1] == '#')
                       deadEnds++;        
                    if(maze[i][j+1] == '#')
                       deadEnds++;     
                    if(deadEnds >= 3)
                       return true;
                 }        
                 deadEnds = 0; //Ensure Reset
            }
        }
        return false;
    }

    How would you approach these problems?
    Last edited by Staticity; February 13th, 2012 at 10:17 PM.
    Simplicity calls for Complexity. Think about it.


Similar Threads

  1. Replies: 3
    Last Post: January 5th, 2012, 01:44 AM
  2. Connecting to Access 2007 Database
    By aussiemcgr in forum JDBC & Databases
    Replies: 12
    Last Post: December 14th, 2010, 04:42 PM