Sudoku Solver Backtracking Algorithm

Dec 5, 2014

It's about a backtracking algorithm trying to solve a sudoku, represented by an array of integer arrays. For testing matters, the start field is empty.

static boolean solve(int[][] field, int i, int j) {
if (filled(field)) {
return legal(field);
} else {
for (int k = 1; k <= 9; k++) {
field[i][j] = k;

[Code] ....

View Replies


ADVERTISEMENT

Sudoku Solver - Scanner Isn't Functioning Properly

Nov 19, 2014

I am working on a program that should take an input file as a command line argument and check if that file contains a valid sudoku solution. Right now the main error I am getting is my scanner isn't functioning properly and is throwing inputMismatchexceptions, but Im also not sure about the validity of my functions, and i cannot test them because my scanner isn't working.

import java.util.Scanner;
 
//This class will read in a possible sudoku solution and test it for validity. If it is invalid, return at least one reason why.

public class SudokuVerifier {
//this function checks a row to see if it contains the numbers 1-9
public static boolean checkRow(int sudoku[][], int i) {
boolean contains=false; // keeps track if the line contains a certain number
for(int k=1; k<=9; k++) { //goes through every number from 1 to 9
for(int j=1; j<sudoku[i].length; j++) { //checks every element in the row to see if it is equal to k

[code]...

View Replies View Related

Build Backtracking Algorithm To Place N Queens On Chess Board Of Nxn With No Threat To Any Queen

Nov 17, 2014

Having some trouble coding this exercise in JAVA:

Build a backtracking algorithm to place n queens on a chess board of nxn, with no threat to any queen.

Using F=parameter, Print only the first result.

Using the same C=parameter, print every possible inlays.

This should work when running with a 4x4 board and an 8x8 board basically.

View Replies View Related

Getting NaN For Roots (Quadratic Solver)

Nov 18, 2014

This was the way I was supposed to write it (every thing separated). Any way, I was wondering why when ever I try to run I only get NaN for roots, and my discriminant is off

/**
* Find roots of quadratic equations
*/
import java.util.Scanner;
public class QuadraticProject {
public static void main(String[] args) {

[Code] ....

View Replies View Related

Maze Backtracking From Text File

Dec 15, 2014

im having 2 simple problems that are for somereason going above my head right now.

1: i need to start the program at the first possible position (row 0 col 0)
2: i need to be able to read multiple mazes in one file.

Code:

import java.io.*;
public class Driver {
private File mapFile = new File("map.txt");
private char[][]maze;
private char pathMarker = '2';
private int row,col,ndx=0;
public static void main(String[] args) {
Driver d = new Driver();

[code]....

View Replies View Related

Recursive Backtracking Solution - How To Cache Answers Into Appropriate Array

Jan 23, 2014

I can often write a recursive backtracking solution, but don't know how to cache the answers into an appropriate array.

For example:

Java Code:

public static int max(int[] costs, int index, int total, int shares) {
if(index >= costs.length) {
return total;
}
int buy = max(costs, index + 1, total - costs[index], shares + 1); // buy one stock
int sell = max(costs, index + 1, total + shares * costs[index], 0); // sell all stocks
return Math.max(total, Math.max(buy, sell)); // compares between buy, sell, and doing nothing
} mh_sh_highlight_all('java');

This is a dynamic programming exercise, but I have no idea what dimensions the dp array should be (I was thinking maybe dp[index][total][shares], but that seemed like overkill). Is this just because my understanding of recursion isn't solid enough or am I missing something else?

View Replies View Related

Sudoku Is Not Working For Few Inputs

Apr 22, 2015

The thing my coding for sudoku is not working for few inputs... it works fine with all its value initially at 0, but when i place numbers more than 4 at random places it stops responding (it doesn't show any value). My assignment is to get a solved sudoku for these values:

//Sample Input:
{0,2,7,3,8,0,0,1,0},
{0,1,0,0,0,6,7,3,5},
{0,0,0,0,0,0,0,2,9},
{3,0,5,6,9,2,0,8,0},
{0,0,0,0,0,0,0,0,0},
{0,6,0,1,7,4,5,0,3},
{6,4,0,0,0,0,0,0,0},
{9,5,1,8,0,0,0,7,0},
{0,8,0,0,6,5,3,4,0}

My current code

public class Sudoku {
static int userGrid[][]=new int[][]
{{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0}};//[horizontal][vertical]
static int grid[][]=new int[9][9];//the grid that the program experiments on

[Code] .....

View Replies View Related

Solver For System Of Linear Equation In Java For Large Matrices (finite Element Program)

Jan 16, 2014

I develop a finite element code at java. I am looking for efficiency solver and fast for large, sparse , symmetric and positive define matrices .

i used in jblas but i encounter in problem when the matrix has high condition number(ill condition number) and i get error for singular matrix while in mathematica i succeed to solve that system without problems...

Any good solver and fast solver package in java can i use for solving that system?

View Replies View Related

How To Write Mini Sudoku In 4x4 Puzzle Using Java

Oct 31, 2014

How to write a mini sudoku in 4x4 puzzle using java The entries of each grid are 1,2,3 or 4 only.

No number will be the on a row.

No number will be the same in a column.

There are 4 regions in the puzzle and no number will be the same in a region.

I want to ask how to finish the below code, because I don't know how to extend using the below code

import java.util.*; 
public class MiniSudoku {
 final static int SIZE=4;

[Code]....

View Replies View Related

Sudoku Checker Program - Cannot Find Symbol

Jul 9, 2014

I can't get the code to compile for the driver every time i get an error message saying

SudokuCheckerTest.java:28: error: cannot find symbol
foo.displayGrid(grid);
^
symbol: variable grid
location: class SudokuCheckerTest
SudokuCheckerTest.java:29: error: cannot find symbol
foo.getGrid(grid);

[Code] .....

4 errors

Java Code :

import java.util.Scanner;
public class SudokuChecker{
public SudokuChecker(){
// displays intro code and initializes the array grid as well as using method calls.
Scanner in = new Scanner(System.in);
int [][] grid = new int [4][4];
displayGrid(grid);

[Code] ....

View Replies View Related

Sudoku - When Place Numbers More Than 4 At Random Places It Stops Responding

Apr 22, 2015

The thing my coding for sudoku is not working for few inputs... it works fine with all its value initially at 0, but when i place numbers more than 4 at random places it stops responding (it doesn't show any value).

My assignment is to get a solved sudoku for these values:

//Sample Input:
{0,2,7,3,8,0,0,1,0},
{0,1,0,0,0,6,7,3,5},
{0,0,0,0,0,0,0,2,9},
{3,0,5,6,9,2,0,8,0},
{0,0,0,0,0,0,0,0,0},
{0,6,0,1,7,4,5,0,3},
{6,4,0,0,0,0,0,0,0},
{9,5,1,8,0,0,0,7,0},
{0,8,0,0,6,5,3,4,0}

My Current code

public class Sudoku {
static int userGrid[][]=new int[][]
{{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0}};//[horizontal][vertical]
static int grid[][]=new int[9][9];//the grid that the program experiments on
public static void main(String[] args) {

[Code] ....

View Replies View Related

Sudoku GUI - How To Make Some Textboxes JDialogs Displaying Uneditable Numbers

Apr 25, 2014

So here is what i have so far for my sudoku game. Now my grid only displays textboxes where a user can input numbers but nothing will happen yet. I want to know how to make it so that the user can only input one character and only numbers. i would also like to know how to make some textboxes jdialogs displaying uneditable numbers that im taking from a sudoku website for the puzzle.

Main Class

import javax.swing.JOptionPane;  
public class Game{
public static void main(String[] args) {
JOptionPane.showMessageDialog(null, "Hello. Welcome to a game of Sudoku by Ezra Zike.");
Level select = new Level();

[Code] .....

View Replies View Related

Binary Search Algorithm

Mar 24, 2014

I am trying to make a program that compares the 3 different search algorithms(sequential/binary/hashing). I have already made the sequential search algorithm, binary and hashing part of the code.My program OPENS a data file, and then OPENS a key data file. and then searches through them using both. How to go about the binary and hashing search algorithm (in the driver program).

*I have included a zip file with:
-base program
-driver program
-data file
-key data file

View Replies View Related

Searching And Sorting Algorithm

Jan 2, 2015

I have a code that is meant to read a file and organize all the names from least to greatest salaries. It also allows the user to enter a name to find from the file, and the program finds the name and displays it. I have two errors, and I will show the error in my code

View Replies View Related

Creation Of Algorithm For Log In With Verification

Feb 7, 2015

I'm making a code for a log in system that allow me to verify if username and psw are correct (using a file txt as refer), and then i will add maybe the possibility to sign up.

The fact is that I want this kind of formatting on the .txt

username psw
username psw
username psw

...etc

So I have to read the lines and split to the " " and compare the insert data and the read data.

Here is my code, it star but give me this error when i insert any word

XML Code:

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 1
at prova.main(prova.java:20) mh_sh_highlight_all('xml'); Java Code: import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class prova {
public static void main(String[] args) throws FileNotFoundException {

[Code] .....

View Replies View Related

Difference Between Algorithm And Programming

Feb 21, 2014

What is difference between algorithm and programming?How to develope algorithm knowledge?

View Replies View Related

Text-to-image Algorithm

Oct 4, 2014

Encryptor

Java Code:

Private Sub cmdDeleteMessage_Click()
If txtMessage.Text = "" Then
a = MsgBox("No message to delete!", vbInformation, "")
Else: If MsgBox("Do you want to create a new message?", vbYesNo, "New") = vbNo Then Exit Sub
txtMessage.Text = ""
Pic.Picture = LoadPicture()

[Code] .....

Is these codes of the Block cipher encryptor for text-to-image algorithm (B-TTIE algorithm) by Abusukhon 2013? If not, how to make it the same with B-TTIE algorithm?

View Replies View Related

How To Create Genetic Algorithm

May 23, 2015

how to create a genetic algorithm.I made this class that Is supposed to Generate the chromes or Possible solutions of the program. Im pretty sure It doesn't have any syntax error and I went over the logic a couple time yet Im getting a NumberFormatException Exception Error. What this error means nor why am I getting it. Here's my code:

/* Contains the genes or possible solutions to the problem
*/
public class Genes
{
/* Each element is a binary number that corresponds to index number they have been assigned to, these are the possible genes
* The last 4 elements in the array represent + - * / correspondingly
*/
private String[] encodedNumbers = {"0000", "0001", "0010", "0011","0100", "0101", "0110","0111","1000","1001","1010","1011","1100","1101"};

[code]...

View Replies View Related

Tic Tac Toe Game - Minimax Algorithm

Jan 4, 2014

I have been trying to create an algorithm for the computer in my Tic-Tac-Toe game? So I searched for some good ones, and found about this confusing but effective algorithm, at least if you get it working, called Minimax. I tried implementing it into my game. Let's say it was easier said than done. Sometimes I think it's working, but sometimes it doesn't work at all. How do I get my algorithm working? What the variables BEST_SCORE_COMPUTER and BEST_SCORE_PLAYER in my code should have as starting values.

Java Code:

import java.util.Scanner;
public class TicTacToe{
private static char BOARD[] = {' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '}; // This is the main board itself.
private static int ROWS[][] = {{0, 1, 2}, {3, 4, 5}, {6, 7, 8}, {0, 3, 6}, {1, 4, 7}, {2, 5, 8}, {0, 4, 8}, {2, 4, 6}}; // These are all the rows one can win by filling.
private static int SCORE, BEST_MOVE_COMPUTER, BEST_SCORE_COMPUTER = -1, BEST_SCORE_PLAYER = 1; // These variables speak for themselves.
private static byte TURN = 1; // 1 means player's turn, and 2 means computer's turn.

[Code] .....

View Replies View Related

Algorithm That Processes Numbers

May 7, 2014

I have a set of numbers within a text file.

2 6
1 4 4 1

When the program reads these numbers it will start with the first line. It reads 2, this is the number of times the program should loop through the numbers of the second line. Next it reads 6, this is the number that the sum of numbers on line 2 cannot go beyond, it must equal 6 or be less than.

Next it goes to line 2 and processes the numbers, 2 is less than 6 so it gets processed, so is 4 and when added to 2 it equals 6. This passes the rules therefore gets processed and added together and put in a variable. Once 2 and 4 has been processed it gets put at the back of the number queue, so the numbers look like 1 1 2 4.

With one loop done there is only one left, so it processes the next sum of numbers 1 1 2 as these equal 4 and pass the rule. So these get added together and and put to the back of the queue, 4 1 1 2. But all the loops are finished and the sum of the last loop is added on to the sum of the previous loop. 6 + 4 = 10.

What I need the algorithm to do is print the sum of this whole process when it reads these numbers from a file. I am able to read the numbers from a text file but not sure where to proceed from there.

Also the set of numbers vary, for example the next 2 lines of numbers could be,

10 7
3 1 1 1 4 4

View Replies View Related

Enable MD2 Algorithm Only For A Particular Place And Not For Whole JVM

Jun 6, 2014

Is it possible to enable & disable "jdk.certpath.disabledAlgorithms" property programmatically. I want to remove all disabled Algorithms for some time and later I will enable it.

Or is it possible to enable only for a particular place & not in a JVM level. I want that Algorithm need to be enabled for a piece of code, but I don't want it to the remaining part of the application.

View Replies View Related

Genetic Algorithm Programming

Oct 13, 2014

I am looking to program a simple genetic algorithm in Java but where to start.

" In a computer language of your choice, implement a simple genetic algorithm (GA). That is, write code for a generational GA which uses a binary encoding, tournament selection, single-point crossover and bit-wise mutation" ....

View Replies View Related

Pseudocode For Quicksort Algorithm

May 6, 2015

I have been given this Pseudocode for the Quicksort algorithm:

quicksort(a[], p, r)
if r>p then
j=partition(a[], p, r)
quicksort(a[], p, j-1)
quicksort(a[], j+1, r)

[code]....

I was wondering why:

- why the condition left < right needs to be true for the while loop in the function Partition
- what the while loop does in the function Partition

View Replies View Related

Checker Game With Minimax Algorithm

Apr 12, 2015

I have a checker game already and I am trying to make an AI opponent even if not so Intelligent as long as it can move chips on its own until the game is over.

View Replies View Related

Search Algorithm Causing StackOverFlowError?

Apr 29, 2015

I am using what is known as a Depth First Search to solve a maze using my own Stack created class for an assignment. The reason I believe I am getting this error is because my program is never meeting the `finishSpot` condition. I have used the debugger and it looks like it is infinitely stuck at the Point before the `finishSpot`. My logic seems to be mostly correct except until the point where my maze solver tries to finish the maze.

This is a sample maze:

*****
*s* *
* * *
* f*
*****

Here is my Main which uses my created Stack class.

//Creates a Stack and determines the start and endpoints.
public static void solveDFS( char [][] maze ){
LinkedStack stack = new LinkedStack();
Point currentSpot = findPoint( maze,'s' );
Point finishSpot = findPoint( maze, 'f' );
findPath( maze,currentSpot, finishSpot,stack );

[code]....

View Replies View Related

Algorithm Of Convert Hex To Floating Point

Aug 13, 2014

I wanna write a program that take an Hexadecimal and convert it to floating-point . what should I do ?

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved