A FORTRAN code for solving Sudoku puzzle

Click For Summary

Discussion Overview

The discussion revolves around writing a FORTRAN code to solve Sudoku puzzles. Participants explore various methodologies, challenges, and alternative approaches to both solving and generating Sudoku puzzles, including brute force methods and transformation rules.

Discussion Character

  • Exploratory
  • Technical explanation
  • Debate/contested
  • Mathematical reasoning

Main Points Raised

  • One participant expresses difficulty in writing a FORTRAN code for solving Sudoku and seeks existing solutions.
  • Another participant shares a Python solution and suggests a book for inspiration, although they have not read it themselves.
  • A participant discusses the relative ease of creating a Sudoku generator compared to a solver, mentioning transformation rules that can generate related puzzles.
  • A proposed methodology for solving Sudoku involves selecting empty cells and incrementally checking for duplicates in rows, columns, and 3x3 squares, though it is acknowledged as inefficient.
  • Another participant suggests a brute force approach that involves treating the Sudoku grid as a large number and validating potential solutions through a series of checks.
  • There is mention of using genetic algorithms to merge potential solutions and evaluate them based on a scoring function.

Areas of Agreement / Disagreement

Participants express differing views on the best approach to solving Sudoku, with some favoring brute force methods while others highlight the complexity of writing a solver compared to a generator. No consensus is reached on a single effective method.

Contextual Notes

Some participants acknowledge their lack of familiarity with certain transformation techniques and express uncertainty regarding the efficiency of proposed methodologies. The discussion includes various assumptions about the nature of Sudoku puzzles and the effectiveness of different solving strategies.

Who May Find This Useful

Individuals interested in programming, algorithm design, and puzzle-solving techniques, particularly those looking to implement solutions in FORTRAN or explore different algorithmic approaches to Sudoku.

yabi
Messages
23
Reaction score
1
For few days I am thinking to write a code in FORTRAN to solve the sudoku puzzle.
At first it seams simple but I have no luck writing this code.
I am wondering if there is any written code to solve this puzzle.
I hope Sudoku puzzle is known for members here.
en.wikipedia.org/wiki/Sudoku
 
  • Like
Likes   Reactions: Arpan Dubey
Technology news on Phys.org
You can get some inspiration from my own solution in python: on my blog.

You may find some help in this book (I haven't read it, but I was told some great things about it).

J.
 
yabi said:
For few days I am thinking to write a code in FORTRAN to solve the sudoku puzzle.
At first it seams simple but I have no luck writing this code.
I am wondering if there is any written code to solve this puzzle.
I hope Sudoku puzzle is known for members here.
en.wikipedia.org/wiki/Sudoku

I'm sure sudoku is well-known to people here. What have you tried? What difficulties are you having?
 
Trying to write a sudoku generator is a lot easier than writing a sudoku solver especially if you start with an existing solution and then use the transformation rules for sudoku:

1) you can reorder any row or col within a group and still have a valid puzzle
2) you can reorder any 3-row or 3-col groups and still have a valid puzzle

from that you can see that you can generate a lot of different but related puzzles.

One question I had though was whether you could generate the complete set of sudoku puzzles or not given one solution and these transformations.
 
Dear Mark
Thanks for your reply. I am trying to draw a flowchart of solution in FORTRAN.
My methodology is as follows:
1- Select each cell with zero value (empty cells are zero) in big square (9x9) starting from top left
2- Put value 1 to the first zero cell.
3- Check this cell with all cells in same row. If they have same value, add one to previous value of cell and check again.
4- repeat item 2 and 3 for same column
5- repeat item 2 and 3 for small square (3x3)
Go to next step.

This methodology is not a wise method and even if it is able to solve, it will take lots of time.
So I think there must be a better solution strategy.
 
Dear Jedish
Thanks for comments. I was unaware of transformations you mentioned. They are interesting however I don't think they might help me to draw a flowchart for solution.
As you wrote, making a generator is lot easier than writing a solution. But I don't have a solution for a given Sudoku.
 
yabi said:
Dear Jedish
Thanks for comments. I was unaware of transformations you mentioned. They are interesting however I don't think they might help me to draw a flowchart for solution.
As you wrote, making a generator is lot easier than writing a solution. But I don't have a solution for a given Sudoku.

Okay so a brute force scheme would be to assign all blank cells with the value of 1 and then consider the cells together as a monster number that you can count thru like 1111111111111111 then 1111111111111112...

Next provide a method to validate a potential solution, ie is the 3x3 square valid, does the row have a duplicate, does the col have a duplicate... if it fails then increment the cell and try again when it hits 9 increment the next cell and reset the first cell to 1 and repeat incrementing the first cell...

Another method would be to generate a set of potential solutions and use a genetic algorithm to merge solutions and a scoring function to evaluate solutions.
 
Dear AlephZero and jedishrfu

Thanks for replies. I have seen the wikipedia page but wanted to try a personal way for solving.
It seams that there are many discussions on the issue and I was unaware of them.
I will read the brute force algorithm thoroughly and let you know what am I up to do.
 

Similar threads

  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 2 ·
Replies
2
Views
1K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 9 ·
Replies
9
Views
2K
  • · Replies 3 ·
Replies
3
Views
5K
  • · Replies 14 ·
Replies
14
Views
5K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K