Win a copy of Kotlin in Action this week in the Kotlin forum!
programming forums Java Java JSRs Mobile Certification Databases Caching Books Engineering OS Languages Frameworks Products This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Sheriffs:
Saloon Keepers:
Bartenders:

# game

christian fabiano
Greenhorn
Posts: 3
i am trying to program a game . its a sudoku game . got an idea of the algorithm but not too sure how to code it. its yo read the puzzle from a file and print out the answer. the puzzle is below. it can be saved onto a seperate file and then soleved.

640013900
100026400
029045700
002000830
860037019
700209000
001300690
936408020
005000000
the pseudocode i derived to solving it is below:

i have a logic and below is can i say a rough pseudocode;
// the sudoku is a 9x9 grid in 9 sections. i also have 10 layers with the 0 layer being my final solution layer and other layers numbered from 1-9. i thought about doing a 3 d array [9][8][8]. or something like that.
//first check if a number can enter any of the boxes starting at 1 all the way to 9.(method-number roll).
//starting at 1, while rolling...... do a section scan(method): this checks the first section to see if number being rolled is in the section.(scan thru all the sections with 1 then after last section, move to 2 then to 9)
// if in section, move to next section
//else do a cell check(method): this checks empty cells in that section.
//for each empty cell, if the number being rolled is not on the same entire row or column, enter it inot its layer eg. if 2 is being rolled, enter the number as a temp solution to the 2nd layer.
//fthe cross out method- after rolling thru with 9, after the last section, then do this method. if a number is the onoly number in its section on the same layer or all layers for a cell, then cross out all similar numbers on the same row, column or section, then move up to the 0 layer.
//print solution layer- when there is no 0/or emptyspace left in the 0 layer, print out the entire 0 layer.

If there is a simpler way of solving it i am open to ideas. as i said earlier just need a code so that i can learn from it.

thanks

Jesper de Jong
Java Cowboy
Sheriff
Posts: 16028
87
Search with Google for "sudoku java" or "sudoku java source". You're not the first person who's writing a Sudoku program... :-)