Generation of sudoku questions - algorithm

I am doing a sudoku game. My problem is the generation of sudoku questions. I want to generate questions in three difficulties. Is there any idea to generate 3 level questions?

If we go for pre generated sudoku puzzles, maybe you could have a look at this :
http://www.setbb.com/phpbb/viewtopic.php?t=102&mforum=sudoku
we used terminal sudoku in the Linux distributions
it has a batch generator mode.
the website is down but it is packaged for some linux distributions.
generate puzzles for each level : easy, medium and hard
sudoku -fcompact -ceasy -g5>sudoku_easy.txt
sudoku -fcompact -cmedium -g5>sudoku_medium.txt
sudoku -fcompact -chard -g5>sudoku_hard.txt
solve the puzzles
sudoku -fcompact -v sudoku_easy.txt >sudoku_easy-resolved.txt
sudoku -fcompact -v sudoku_medium.txt >sudoku_medium-resolved.txt
sudoku -fcompact -v sudoku_hard.txt >sudoku_hard-resolved.txt
I checked some of them and they had only one solution.

Generate full (filled) sudokus and before printing the sudoku out, make some percentage of the fields empty again for the human to fill.
Select random fields to empty. Raise the percentage of empty fields on each difficulty level.

Related

GEKKO Singular Matrix Problem with BPOPT and Solver Selection

I used MODES = 7 to sequentially solve a simulation problem with BPOPT solver. The solver can solve the first few problems but report the following error:
*** WARNING MESSAGE FROM SUBROUTINE MA27BD *** INFO(1) = 3
MATRIX IS SINGULAR. RANK= 581
Problem with linear solver, INFO: 3
With solver=0, I can see the GEKKO has 6 different solvers. I wonder how can I specify a solver (like MINOS).
You can change solvers with m.options.SOLVER=1 for APOPT or m.options.SOLVER=3 for IPOPT. The other solvers aren't available for public use because they require a license.
The error message that you are receiving is because the solver could not find a search direction. I recommend including variable bounds such as lower bound of zero for some variables to prevent singular solutions.
If you'd like more specific help, please post minimal, verifiable code.

Can someone clarify me the differences between a Program and an Algorithm? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
So, I have been doing a little research and searching around Google about Algorithms. I was getting the hang of it until I got a little deeper.
I understand that an Algorithm is defined as: a process or set of rules to be followed in calculations or other problem-solving operations, especially by a computer (Quoted from Dictionary). A Computer Program is defined as: is a sequence of instructions, written to perform a specified task on a computer (Quoted from Wikipedia)
An analogy I saw on a thread helped me a little bit:
Cake Algorithm:
--Get Ingredients
--Bake
--Serve
Cake Program:
--2fl of flour
--3 eggs
--Mix in pan
--etc.
As I saw the algorithm was more general
So basically how I began to think of a computer program was code that implements the Algorithm, in other words the Algorithm is a blueprint. For example, this is a simple Algorithm:
Step 1: Start
Step 2: Declare variables num1, num2 and sum.
Step 3: Read values num1 and num2.
Step 4: Add num1 and num2 and assign the result to sum.
sum=num1+num2
Step 5: Display sum
Step 6: Stop
I am also aware after more google searches that Algorithms can be represented in pseudo-code:
if a>b
Display a is bigger than b #Simple Example, but you get the point
They can also be formed in real code (making the algorithm as you go) like this:
def foo():
#Blank Code for Algorithm/to be used later
So now this is where my question comes in, a lot of stackoverflow threads I see ask a user to explain/correct their algorithm. However, when I look at the algorithm instead of seeing something like the above examples I will see this:
// I know this isn't Python but that's not the point!
for (int i = 0; i < N; i++) {Console.Write('Hello World !');
}
No blank functions/empty code blocks, its all filled in and such
So now my questions:
Is the above code for example indeed an Algorithm? Or is it a program written that follows a Algorithm?
If it is considered an Algorithm, what is the difference between that being an Algorithm, and that code being a computer program?
If it is both, does that mean the two terms can be used interchangeably?
Any clarification to a beginner would be nice.
// I know this isn't Python but that's not the point!
for (int i = 0; i < N; i++) {
Console.Write('Hello World !');
}
Is the above code for example indeed an Algorithm? Or is it a program
written that follows a Algorithm?
Nope. If you were to remove the printing part and just add print hello world instead of Console.Write(), it could be an algorithm to print hello world N times.
If it is considered an Algorithm, what is the difference between that
being an Algorithm, and that code being a computer program?
An algorithm is language independent, it just shows how to do something, the language defines a stricter set of rules on how to implement something. A program is used to implement an algorithm considering the rules and syntax defined by a language .
If it is both, does that mean the two terms can be used
interchangeably?
Nope. An algorithm is not language specific whereas a program is always used in conjunction with a programming language.
Sample statement : Write a Java program to implement BubbleSort algorithm.
First of all welcome to StackOverflow and the world of coding.
The answers to your questions:
1.Is the above code for example indeed an Algorithm? Or is it a program written that follows a Algorithm?
The above code is a "program" . An algorithm is like you said the blueprint and the whole architecture itself.
The algorithm for the above code could be:
STEP 1: START
STEP 2: Print Hello World 5 times. (That's it actually)
STEP 3: END
You see the algorithm is something which describes a code in simple plain language. You can explain the blueprint of a program in pseudo code or a flowchart. You can't feed it to the PC without actually giving it the form the PC will accept. Therefore You need to convert it into a program using languages like C ,CPP, Python etc
2.If it is considered an Algorithm, what is the difference between that being an Algorithm, and that code being a computer program?
WELL that's is not the algorithm as described above. And the answer to remaining part is explained as above
3.If it is both, does that mean the two terms can be used interchangeably?
No, it shouldn't be because of the exact same reason stated above.
Hope You get it.
Cheers
Same difference as between a class and an instance object.

LightsOut game solving method "reduced echolean ".Does it always gives correct result?

I am studing the algorithm given here, and
somewhere it is claimed that it is efficent and always give correct result.
But, I try to run the algorithm and it is not giving me correct or efficent output for the following patterns.
For 5 x 5 grid, where (n) is light number and 0/1 state whethere the light is on/off, 1 ON and 0 OFF.
(1)1 (2)0 (3)0 (4)0 (5)0 the output should be 1,7,13,19,25(Pressing this light will make the full grid OFF. But what I am getting is this
(6)0 (7)1 (8)0 (9)0 (10)0 3,5,6,7,8,10,13,16,18,19,20,21,23.
(11)0 (12)0 (13)1 (14)0 (15)0
(16)0 (17)0 (18)0 (19)1 (20)0
(21)0 (22)0 (23)0 (24)0 (25)1
While for some pattern it is giving me correct output as below.
(1)0 (2)0 (3)0 (4)0 (5)1 the output should be 5,9,13,17,21, and the algorithm is giving me correct result.
(6)0 (7)0 (8)0 (9)1 (10)0
(11)0 (12)0 (13)1 (14)0 (15)0
(16)0 (17)1 (18)0 (19)0 (20)0
(21)1 (22)0 (23)0 (24)0 (25)0
If somebody need a code let me know I can post it.
Can please somebody let me know if this methods will always give correct as well as efficient result or not ?
(I'm the author of the code you linked to.) To the best of my knowledge, the code is correct (and I'm sure that the high-level algorithm of using Gaussian elimination over GF(2) is correct). The solution it produces is guaranteed to solve the puzzle, though it's not necessarily the minimal number of button presses. The "efficiency" I was referring to in the writeup refers to the time complexity of solving the puzzle overall (it can solve a Lights Out grid in polynomial time, as opposed to the exponential-time brute-force solution of trying all possible combinations) rather than to the "efficiency" of the generated solution.
I actually don't know any efficient algorithms for finding a solution requiring the minimum number of button presses. Let me know if you find one!
Hope this helps!

Running Sudoku Solver Example in hadoop

I am trying to run sudoku solver provided with hadoop example jar file. I am not sure the format in which input is supposed to be given. Can anybody guide?
Thanks,
Tapan
From the documentation:
The sudoku solver is so fast, I didn't bother making a distributed
version. (All of the puzzles that I've tried, including a 42x42 have
taken around a second to solve.) On the command line, give the solver
a list of puzzle files to solve. Puzzle files have a line per a row
and columns separated by spaces. The squares either have numbers or
'?' to mean unknown.

Where to get Sudoku generator in C++?

Here is one - http://ostermiller.org/qqwing/
But sometimes my PHP code (shell_exec('qqwing..')) dies and in syslog I can find segfault errors for qqwing.
So, I'm searching for better generator, but can't find one. Fast and with difficulty levels.
Any suggestions?
Sudokuki is a graphical SUDOKU game: Set up a custom sudoku from a magazine or so - Generate a sudoku - Solve a sudoku - Print a sudoku. Translated into: de, en, el, eo, es, fr, ja. Sudokuki is multiplatform GNU/GPL Free Software, in C++
http://sourceforge.net/projects/sudokuki/
If that isn't quite what you want, for some reason, then search further roon SF. I git 292 hits when searching for sudoku

Resources