Board Coloring, JAVA Programming

BoardColoring.java program for 2D MXM matrix
Posted Date: 8/30/2012 3:50:04 AM | Location : United States







Board Coloring

Problem Description


In this problem you are given a board in which some of the elements are placed as shown in diagram below. Each element represents a color.
Fill the other elements in the board, such that none of the adjacent elements (vertically, horizontally and diagonally) should be of the same color.
Find out the minimum number of colors that should be used to fill the blank spaces in the board, so that the above condition is met.
Color representation is -: 0, 1, 2, 3, 4, 5, 6, 7…………………….
There is sample board:

For Example:

Given Board :

The matrix representation of board is :
[ _ 1 _ _ ]
[ 2 _ _ _ ]
[ _ _ 2 _ ]
[ 2 _ _ _ ]
In the above example the blank space is represented by ''_'' .
The minimum number of colors needed to fill the board in the example is 4.

Instruction to work with Open PBT Client:

Specify the work directory path in the ''Work Directory Path'' field. The path should correspond to your solution project directory.
Download the support files by clicking the Get Dev Files.
You will find the following three folders:
bin
src
lib
in your work directory.
Code the solution in . java file inside the src folder
All required files will be downloaded to your work directory. Creating additional files is strongly discouraged.

Step 1:
In your solution file:

Implement your logic in public int color(char[][] board) in class BoardColoring .
char[][] board : board is 2 dimensional matrix of order M X M where M = 4.

You can create more methods but, do it in the same class.

Step 2:
In your solution keep in mind the following constraints.

In this problem you have to write a program to find the minimum no of colors to fill a board where some of the elements of different color are already placed.
Method color() will take 2 D board as a input.
Method color() will return minimum no of colors which can fill the board with given condition.
The board should be a 2-dimensional M X M matrix, where M =4 otherwise return 0
Fill the other elements in the board, such that none of the adjacent elements (vertically, horizontally and diagonally) should be of the same color.

The Prototype of the method is:

public int color(char[][] board).
This method takes following arguments.

board is 2 dimensional matrix of order M X M where M = 4.

This method returns minimum no of color by which board can be filled.

The constraints are:

The board should be a 2-dimensional M X M matrix, where M =4 otherwise return 0
Fill the other elements in the board, such that none of the adjacent elements (vertically, horizontally and diagonally) should be of the same color.

Example 1
Input : { 2 0 _ 1 }
{ _ 1 _ _ }
{ _ 2 _ 0 }
{ _ _ _ 1 }
Output : 5

Explanation:
We need a minimum 5 different colors to complete the board.

Example 2
Input : { 2 0 _ 1 3}
{ _ 1 _ _ 2}
{ _ 2 _ 0 1}
{ _ _ _ 1 2}
{ _ _ _ _ 0}
Output : 0


Explanation:
Size of the board is greater than 4X4.

Example 3
Input : { _ 0 }
{ 1 _ }
Output : 0


Explanation:
Size of the board is less than 4X4.

For Java solutions
Package Name : test.boardcoloring
File Name : BoardColoring.java
Class Name : BoardColoring
Method Names : public int color(char[][] board)
Posted by diana | Posted Date: 9/4/2012 4:24:08 AM


Related Discussions:- Board Coloring, Assignment Help, Ask Question on Board Coloring, Get Answer, Expert's Help, Board Coloring Discussions

Write discussion on Board Coloring
Your posts are moderated
Related Questions
What is a packet within the network environment? What kind of information does it contain? A packet is the shortest unit of data transmitted over a computer network. It's a mes

Farm Production System Project Description: I require software that will allow me to input/record the daily production of our farm and allow me to view the data back in the o

Java has two kinds of exceptions: 1. Checked exception: handled from java.lang.Exception but not java.lang.RuntimeException. 2. Unchecked exception: handled from java.lang.Ru

Difference between the File and Random Access File classes? Ans) The File class encapsulates the files and directories of the local file system. The Random Access File class giv

How to draw Polygons in java? In Java rectangles are defined through the position of their upper left hand corner, their height, and their width. Therefore it is implicitly sup

Overall Requirements Every phone number is broken up into sections as shown below: Country Code Area Code Prefix Line Number 1 919 882 5000 Write a program to separate out a ph

Explain how many ways businesses monitor their employees? • Systems are available which monitor almost every key stroke that an employee forms on a computer. • Systems are avai

1.) Write an application with two user transactions (login which includes viewAllStudents and viewStudent ) with full MVC architecture that displays the details of the selected

Question: (a) Draw out a UML class diagram that captures the following information: An Employee is a kind of Person. An ATM is a kind of Machine. Both an Employee and an ATM

Project Description: I need a new payment gateway of my own. I mean new payment gateway not any integration. So please bid only if you had made a payment gateway former like