Sudoku solver with GUI

34 views
Skip to first unread message

Tzach

unread,
Feb 6, 2009, 9:22:33 AM2/6/09
to Clojure
Hi all
As my first Clojure project, I decided to finally solve one of
humanity major problems - Sudoku!
Here is the source
http://code.google.com/p/sudoku-solver/source/browse/trunk/sudoku-solver.clj

I would appreciate your comments.
Thanks Konrad for useful tips.

What is the simplest way to make a standalone executable out of this?

Thanks

Keith Bennett

unread,
Feb 6, 2009, 9:54:59 AM2/6/09
to Clojure
Tzach -

Cool!

I had to do some things to get it to work.

* Reversed the order of parse-digit and abs functions.

* Added call to -main at the end. By the way, what is the
significance of the hyphen in the function name?

* The call to msg-box in the About action had an extra parameter,
nil. I removed it. I presume the call used to be to the JOptionPane
static method call, and after refactoring it to use the shared msg-box
function, you forgot to remove the nil?

I pasted a copy of my version at http://www.pastie.org/381649.

Thanks,
Keith

Laurent PETIT

unread,
Feb 6, 2009, 6:36:12 PM2/6/09
to clo...@googlegroups.com
Hello, not related to your question, but  you should consider renaming your file sudoku_solver to make it compiler friendly.

Concerning your question, I think there have been some answers recently on the ml. Sorry I don't remember the links exactly.

Regards,

--
Laurent

2009/2/6 Tzach <tzach.l...@gmail.com>

Laurent PETIT

unread,
Feb 6, 2009, 6:41:33 PM2/6/09
to clo...@googlegroups.com
Hello Keith,

2009/2/6 Keith Bennett <keithr...@gmail.com>


Tzach -

Cool!

I had to do some things to get it to work.

* Reversed the order of parse-digit and abs functions.

* Added call to -main at the end.  By the way, what is the
significance of the hyphen in the function name?

Please, consider that it is a bad idea/practice (in general) to emit calls to functions in a namespace/lib.

Indeed, if I try your version of the code in eclipse with clojuredev (but that would be the same problem with other IDEs as well), whenever the file gets recompiled, it will launch the main function ! Because in clojure, compile is really a 'compile and 'load feature.

I think the -main function is here to implement the main() method of the java class that the :gen-class directive of the namespace declaration has.

Since there has been no specific prefix specified, all functions that will be part of the generated class will just begin with -.

If Tzach had put a prefix to, say sudoku , then the main java method method would have been mapped to the sudoku-main clojure function. Please see http://clojure.org/compilation and the docstrings of ns and gen-class for more detail.

Regards,

--
Laurent
 

Tzach

unread,
Feb 7, 2009, 3:58:08 AM2/7/09
to Clojure
Thanks Keith, I update the version with your inputs, should have test
it first.
Laurent, is it consider a bad practice to use hyphen on general, or
just as ns / file names?

Tzach

On Feb 7, 1:36 am, Laurent PETIT <laurent.pe...@gmail.com> wrote:
> Hello, not related to your question, but  you should consider renaming your
> file sudoku_solver to make it compiler friendly.
>
> Concerning your question, I think there have been some answers recently on
> the ml. Sorry I don't remember the links exactly.
>
> Regards,
>
> --
> Laurent
>
> 2009/2/6 Tzach <tzach.livya...@gmail.com>
>
>
>
> > Hi all
> > As my first Clojure project, I decided to finally solve one of
> > humanity major  problems - Sudoku!
> > Here is the source
>
> >http://code.google.com/p/sudoku-solver/source/browse/trunk/sudoku-sol...

Laurent PETIT

unread,
Feb 7, 2009, 4:09:46 AM2/7/09
to clo...@googlegroups.com
From what I know, it's a good pratice to use hypens and lower case letters in general in the "lisp" world, and it is also a good rule in clojure.

But since namespaces and java classes don't accept hyphens, it is already hard coded in clojure that hyphens are replaced with underscores in namespaces/libs name, when trying to resolve to a classpath entry.

I think there could be one place where sticking to the "lisp way" of writing things is not interesting : if you intend to generate java classes that you want to expose to regular java people : then I think it's better to follow the java conventional form : all lower case package names (no underscores, thus no hyphen), and camel case first first Upper Letter for class names (and no hyphens/underscores).

My 0,02€,

--
Laurent


2009/2/7 Tzach <tzach.l...@gmail.com>

Mibu

unread,
Feb 7, 2009, 8:13:57 AM2/7/09
to Clojure
If you want to test your code, you can use the 50 sudokus from Project
Euler problem 96:

http://projecteuler.net/index.php?section=problems&id=96

You will have to register and log in to check your answer.

On Feb 6, 4:22 pm, Tzach <tzach.livya...@gmail.com> wrote:
> Hi all
> As my first Clojure project, I decided to finally solve one of
> humanity major  problems - Sudoku!
> Here is the sourcehttp://code.google.com/p/sudoku-solver/source/browse/trunk/sudoku-sol...
Reply all
Reply to author
Forward
0 new messages