running test after fixing the counter gives the following <div><div>Solved 95 of 95 puzzles from top95.txt in 2.235227 secs (42.50 Hz)</div><div><div>(210794 total eliminations, avg 2218.88, median 1536, max 10664, min 648).</div>
<div><br></div><br><div class="gmail_quote">On Sun, Mar 27, 2011 at 11:21 PM, Ahmed Omar <span dir="ltr"><<a href="mailto:spawn.think@gmail.com">spawn.think@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<font face="verdana, sans-serif">No problem, as said before u can also replace these lines : </font><div><font face="verdana, sans-serif"><br></font><div><div><font face="verdana, sans-serif">PeerSet = gb_sets:from_list(NonUniquePeers),</font></div>
<div><font face="verdana, sans-serif">PeersWithSelf = gb_sets:to_list(PeerSet),</font></div><div><font face="verdana, sans-serif">lists:delete(Square, PeersWithSelf).</font></div>
<div><font face="verdana, sans-serif"><br></font></div><div><font face="verdana, sans-serif">with just</font></div><div><font face="verdana, sans-serif"><br>
</font></div><div><font face="verdana, sans-serif"><span style="line-height:17px;white-space:pre-wrap">lists:delete(Square, </span><span style="line-height:17px;white-space:pre-wrap"></span><span style="line-height:17px;white-space:pre-wrap"><span style="line-height:normal;white-space:normal">lists:usort(</span></span><span style="line-height:17px;white-space:pre-wrap"></span><span style="line-height:17px;white-space:pre-wrap">NonUniquePeers)).</span></font></div>
<div><font face="verdana, sans-serif"><span style="line-height:17px;white-space:pre-wrap"><br></span></font></div><div><font face="verdana, sans-serif"><span style="line-height:17px;white-space:pre-wrap">(don't forget to check the rest of the thread too ;))</span></font></div>
<div><div><div></div><div class="h5"><br><div class="gmail_quote">On Sun, Mar 27, 2011 at 11:02 PM, Andreas Pauley <span dir="ltr"><<a href="mailto:apauley@gmail.com" target="_blank">apauley@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Thanks!<br>
I didn't think about the sets at all :-)<br>
<br>
<a href="https://github.com/apauley/sudoku-in-erlang/commit/a02fbcd001a9fbd876725008d58c52fcff9872d9" target="_blank">https://github.com/apauley/sudoku-in-erlang/commit/a02fbcd001a9fbd876725008d58c52fcff9872d9</a><br>
<div><div></div><div><br>
On Sat, Mar 26, 2011 at 9:08 PM, Ahmed Omar <<a href="mailto:spawn.think@gmail.com" target="_blank">spawn.think@gmail.com</a>> wrote:<br>
> using gb_sets instead of sets could decrease eliminations a bit and give u<br>
> some boost. However, i didn't dive deeper into the code or the algorithm.<br>
><br>
> On Sat, Mar 26, 2011 at 9:41 AM, Andreas Pauley <<a href="mailto:apauley@gmail.com" target="_blank">apauley@gmail.com</a>> wrote:<br>
>><br>
>> Thanks, I've changed the compile options and this definitely makes it<br>
>> somewhat faster:<br>
>><br>
>> <a href="https://github.com/apauley/sudoku-in-erlang/commit/b7ce2abb6ca013850ed8f3e8fd7f5f6be7004cbb" target="_blank">https://github.com/apauley/sudoku-in-erlang/commit/b7ce2abb6ca013850ed8f3e8fd7f5f6be7004cbb</a><br>
>><br>
>> Strangely the native flag is not documented here:<br>
>> <a href="http://www.erlang.org/doc/man/compile.html#file-2" target="_blank">http://www.erlang.org/doc/man/compile.html#file-2</a><br>
>><br>
>> The more interesting improvement would be to decrease the number of<br>
>> eliminations performed, but for that I'll have to go deep into the<br>
>> code :-)<br>
>><br>
>><br>
>> On Sat, Mar 26, 2011 at 12:16 AM, Evans, Matthew <<a href="mailto:mevans@verivue.com" target="_blank">mevans@verivue.com</a>><br>
>> wrote:<br>
>> > Without going deep into the code, one thing to try is compile with the<br>
>> > native flag (running the tests from the VM shell here):<br>
>> ><br>
>> > Without native set:<br>
>> > 18> c(sudoku).<br>
>> > {ok,sudoku}<br>
>> > 19> sudoku:print_results("top95.txt", "\n").<br>
>> > Solved 95 of 95 puzzles from top95.txt in 2.038825 secs (46.60 Hz)<br>
>> > (922678 total eliminations, avg 9712.40, median 6596, max 55370, min<br>
>> > 1797).<br>
>> > ok<br>
>> ><br>
>> ><br>
>> > With native set:<br>
>> > 20> c(sudoku,[native]).<br>
>> > {ok,sudoku}<br>
>> > 21> sudoku:print_results("top95.txt", "\n").<br>
>> > Solved 95 of 95 puzzles from top95.txt in 1.613416 secs (58.88 Hz)<br>
>> > (922678 total eliminations, avg 9712.40, median 6596, max 55370, min<br>
>> > 1797).<br>
>> ><br>
>> ><br>
>> ><br>
>> > -----Original Message-----<br>
>> > From: <a href="mailto:erlang-questions-bounces@erlang.org" target="_blank">erlang-questions-bounces@erlang.org</a><br>
>> > [mailto:<a href="mailto:erlang-questions-bounces@erlang.org" target="_blank">erlang-questions-bounces@erlang.org</a>] On Behalf Of Andreas Pauley<br>
>> > Sent: Friday, March 25, 2011 8:15 AM<br>
>> > To: <a href="mailto:erlang-questions@erlang.org" target="_blank">erlang-questions@erlang.org</a><br>
>> > Subject: [erlang-questions 4] A sudoku solver in Erlang compared to<br>
>> > Python<br>
>> ><br>
>> > Hi all,<br>
>> ><br>
>> > In my quest to learn Erlang I've translated Peter Norvig's sudoku<br>
>> > solver into Erlang:<br>
>> > <a href="https://github.com/apauley/sudoku-in-erlang" target="_blank">https://github.com/apauley/sudoku-in-erlang</a><br>
>> ><br>
>> > For comparison, my slightly modified version of Norvig's Python code<br>
>> > can be found here:<br>
>> > <a href="https://github.com/apauley/sudoku-by-norvig" target="_blank">https://github.com/apauley/sudoku-by-norvig</a><br>
>> ><br>
>> > I like the pattern matching, it was fun to do the entire solution<br>
>> > without a single if or case statement :-)<br>
>> > Something that bothers me though is that the Python solution seems to<br>
>> > be faster, even after I've made the Erlang solution use multiple<br>
>> > processors.<br>
>> ><br>
>> > In order to compare the two solutions I counted the number of<br>
>> > eliminations each performed.<br>
>> > The eliminate function is the core of the solution, for example<br>
>> > assigning a single value to a square is implemented as the elimination<br>
>> > of all other values.<br>
>> ><br>
>> > With the Erlang implementation I get:<br>
>> > sudoku-in-erlang$ ./sudoku<br>
>> > All tests passed :-)<br>
>> > Solved 50 of 50 puzzles from easy50.txt in 2.890978 secs (17.30 Hz)<br>
>> > (93403 total eliminations, avg 1868.06, median 1810, max 2517, min<br>
>> > 1770).<br>
>> > Solved 95 of 95 puzzles from top95.txt in 22.004369 secs (4.32 Hz)<br>
>> > (922678 total eliminations, avg 9712.40, median 6596, max 55370, min<br>
>> > 1797).<br>
>> > Solved 11 of 11 puzzles from hardest.txt in 0.851678 secs (12.92 Hz)<br>
>> > (32339 total eliminations, avg 2939.91, median 2894, max 4779, min<br>
>> > 1781).<br>
>> ><br>
>> > And with the Python implementation:<br>
>> > sudoku-by-norvig$ ./sudoku.py<br>
>> > All tests pass.<br>
>> > Solved 50 of 50 puzzles from easy50.txt in 0.792008 secs (63.13 Hz)<br>
>> > (33059 total eliminations, avg 661.00, median 648, max 830, min 648).<br>
>> > Solved 95 of 95 puzzles from top95.txt in 5.903875 secs (16.09 Hz)<br>
>> > (221997 total eliminations, avg 2336.00, median 1492, max 11512, min<br>
>> > 648).<br>
>> > Solved 11 of 11 puzzles from hardest.txt in 0.237532 secs (46.31 Hz)<br>
>> > (9436 total eliminations, avg 857.00, median 817, max 1198, min 648).<br>
>> ><br>
>> > So according to the stats above, the Python solution performs less<br>
>> > computations when given exactly the same input.<br>
>> > The Erlang code is as close to the Python as I could make it, I've<br>
>> > done more or less a direct translation of the algorithms used.<br>
>> ><br>
>> > I suspect that there are some lazy evaluation happening in the Python<br>
>> > version, possibly generators, although I haven't pinpointed it yet.<br>
>> ><br>
>> > How can I improve my Erlang code in this solution?<br>
>> ><br>
>> > Kind regards,<br>
>> > Andreas<br>
>> > _______________________________________________<br>
>> > erlang-questions mailing list<br>
>> > <a href="mailto:erlang-questions@erlang.org" target="_blank">erlang-questions@erlang.org</a><br>
>> > <a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
>> ><br>
>> _______________________________________________<br>
>> erlang-questions mailing list<br>
>> <a href="mailto:erlang-questions@erlang.org" target="_blank">erlang-questions@erlang.org</a><br>
>> <a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
><br>
><br>
><br>
> --<br>
> Best Regards,<br>
> - Ahmed Omar<br>
> <a href="http://nl.linkedin.com/in/adiaa" target="_blank">http://nl.linkedin.com/in/adiaa</a><br>
> Follow me on twitter<br>
> @spawn_think<br>
><br>
</div></div></blockquote></div><br><br clear="all"><br></div></div>-- <br><div class="im">Best Regards,<br>- Ahmed Omar<div><a href="http://nl.linkedin.com/in/adiaa" target="_blank">http://nl.linkedin.com/in/adiaa</a></div>
<div>Follow me on twitter</div>
<div><a href="http://twitter.com/#!/spawn_think" target="_blank">@spawn_think</a></div><br>
</div></div></div></div>
</blockquote></div><br><br clear="all"><br>-- <br>Best Regards,<br>- Ahmed Omar<div><a href="http://nl.linkedin.com/in/adiaa" target="_blank">http://nl.linkedin.com/in/adiaa</a></div><div>Follow me on twitter</div><div><a href="http://twitter.com/#!/spawn_think" target="_blank">@spawn_think</a></div>
<br>
</div></div>