News for hackers. Stuff that matters.
Re:Sudoku Solver in 140 bytes by po on Wednesday September 28, 2011 @07:40AM (#3047380)
For those of you who haven't heard of code golf, you should check out http://140byt.es/ The point is more to learn more about the language than to make something practical so come at it in a lighthearted way. In this case, the problem is actually pretty damn hard.

140 Bytes is Jed Schmidt's side project where people compete to make useful functions as small as possible. Jed is kind of a Javascript powerhouse and also happens to be a really nice guy.

https://github.com/jed

https://github.com/jed/140bytes/wiki/Byte-saving-techniques

Edited to add.. As a curiosity, Jed might have the most-forked gist on github: https://gist.github.com/962807

Re:Sudoku Solver in 140 bytes by icebraining on Wednesday September 28, 2011 @08:14AM (#3047473)
> For those of you who haven't heard of code golf, you should check out http://140byt.es/

The Code Golf SE site is nice too: http://codegolf.stackexchange.com/

Re:Sudoku Solver in 140 bytes by swannodette on Wednesday September 28, 2011 @08:48AM (#3047572)
Here's one half the size in k:

  p,:3/:_(p:9\:!81)%3
  s:{*(,x)(,/{@[x;y;:;]'&21=x[&|/p[;y]=p]?!10}')/&~x}
http://thesweeheng.wordpress.com/2008/11/30/more-sudoku-solv...
Re:Sudoku Solver in 140 bytes by phzbOx on Wednesday September 28, 2011 @09:53AM (#3047818)
It would be great to have a javascript translation to compare it. This is still pretty amazing.
Re:Sudoku Solver in 140 bytes by silentbicycle on Wednesday September 28, 2011 @11:01AM (#3048145)
You'd have to translate k's entire data model first. It's based on data-parallel, implicit looping over vectors -- like multiplying an entire vector by a constant in linear algebra.

For an open-source implementation of a k-like language, check out Kona (https://github.com/kevinlawler/kona). (Full disclosure, I'm a contributor.) It's still a work in progress, but it's pretty far along.

Re:Sudoku Solver in 140 bytes by 0x12 on Wednesday September 28, 2011 @07:20AM (#3047328)
That's really neat, a sudoku solver that fits in a tweet.

The license is even nicer, that's a real gem, and I think it ought to be submitted for formal approval as an open source license.

Re:Sudoku Solver in 140 bytes by snippyhollow on Wednesday September 28, 2011 @07:55AM (#3047414)
It is http://www.gnu.org/licenses/license-list.html#WTFPL . The WTFPL is from an ex-Debian project leader, also one of the original authors of VLC: http://en.wikipedia.org/wiki/Sam_Hocevar
Re:Sudoku Solver in 140 bytes by ashishgandhi on Wednesday September 28, 2011 @07:21AM (#3047334)
A fork for 139 byes: https://gist.github.com/1247640

And I had never heard of "DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE". (http://en.wikipedia.org/wiki/WTFPL)

Re:Sudoku Solver in 140 bytes by alastairpat on Wednesday September 28, 2011 @09:25AM (#3047717)
I like that the OSI raised the WTFPL licence at a 2009 Board Meeting. I feel the outcome, 'Reject', is a loss for open source software - I'd love to see a programme with LICENCE.TXT containing that.
Re:Sudoku Solver in 140 bytes by sp332 on Wednesday September 28, 2011 @10:38AM (#3048041)
As snippyhollow pointed out above, the FSF recognizes it as a free license. http://www.gnu.org/licenses/license-list.html#WTFPL It's even GPL compatible!
Re:Sudoku Solver in 140 bytes by todsul on Wednesday September 28, 2011 @11:15AM (#3048232)
This won't work for anything but the most basic puzzles. Brute force just constitutes basic gameplay. To solve a moderately advanced Sudoku puzzle you need to compare potential candidates in groups. Then it gets even more advanced with a handful of trial and error techniques.
Re:Sudoku Solver in 140 bytes by T-hawk on Wednesday September 28, 2011 @11:25AM (#3048309)
This is not correct. If a Sudoku puzzle has one and only one solution, brute force can always find it. It is trial-and-error for every single cell and every possible value, which is guaranteed to succeed eventually. Sounds crazy for a human, but a 3 GHz computer microprocessor can rip through that in a second or two.

http://en.wikipedia.org/wiki/Sudoku_algorithms#Solving_Sudok...

Re:Sudoku Solver in 140 bytes by makomk on Wednesday September 28, 2011 @07:58PM (#3050491)
Well, a few seconds unless someone goes and feeds you a worst-case puzzle like the one in that wikipedia page anyway. (Yes, that is an entirely valid sudoku with a unique solution. In theory it can even be solved by hand quite easily by applying a simple set of rules. I checked both of these, though not manually.)
Re:Sudoku Solver in 140 bytes by HankMcCoy on Wednesday September 28, 2011 @04:18PM (#3049687)
Could someone help with the syntax on line 24:

g&&R(a)

I simply don't understand it as a statement and I don't get in the context of the for-loop

Re:Sudoku Solver in 140 bytes by rimantas on Wednesday September 28, 2011 @05:51PM (#3050074)
http://en.wikipedia.org/wiki/Short-circuit_evaluation The same applies to i--||+a in the first loop.
Re:Sudoku Solver in 140 bytes by mrud on Wednesday September 28, 2011 @05:48PM (#3050061)
if g is true call the function R with the parameter a
Re:Sudoku Solver in 140 bytes by thmzlt on Wednesday September 28, 2011 @08:13AM (#3047470)
4clojure has a code golf league for its exercise: http://4clojure.com/
Re:Sudoku Solver in 140 bytes by whatgoodisaroad on Wednesday September 28, 2011 @11:49AM (#3048470)
I want to see a minimal solution in APL.
Re:Sudoku Solver in 140 bytes by HankMcCoy on Wednesday September 28, 2011 @04:27PM (#3049731)
I have to admit, I have never seen

.) for-loops used this way

.) an OR-operator in a for loop

.) +a as a shortcut for a.toString()

.) syntax like g&&R(a) (line 24)

.) syntax like a[j^i==j] (line 29)

Where can I learn/read about advanced stuff like this, searching for this information on google is very hard, as I lack the correct terms ...

Re:Sudoku Solver in 140 bytes by tikhonj on Wednesday September 28, 2011 @06:50PM (#3050258)
I think most of that syntax isn't so much "advanced" as simply not used in practice--it's too hard too read. Additionally, it uses basic operators which you should know (except maybe for "^" which is bitwise xor).

The best thing to do would be go through the basics of JavaScript and learn exactly how everything behaves. You should be able to answer questions like "is 24&&4 === true?" pretty easily.

If you have a bit of time on your hands, reading the standard will teach you all you need to know.

Of course, from a purely professional stand point, this is probably not the best use of your time (although knowing the language inside-out is important); using code like this in production code is a bad idea--it makes maintenance much more difficult.

Re:Sudoku Solver in 140 bytes by veyron on Wednesday September 28, 2011 @08:35AM (#3047523)
What's the minimal `J` solution?