3 ms·
K notation is a bit longer: generalized n queen with board display is qn:{[n],/{:[n=#x;,x;,/_f'f x,\:/:(!n)_dvl,/x]}'(f:0 -1 1+/:)@!n} bd:{[p]`0:".Q"p=\:!#p}
by beagle3 13y ago
K notation is a bit longer: generalized n queen with board display is
qn:{[n],/{:[n=#x;,x;,/_f'f x,\:/:(!n)_dvl,/x]}'(f:0 -1 1+/:)@!n}
bd:{[p]`0:".Q"p=\:!#p}
(see http://nsl.com/papers/qn.htm http://nsl.com/papers/qn.htm)
I suspect that a binary length-optimized encoding of K will be comparably short.
And take into account that K was not designed for code golf - it's just a side effect of optimizing for orthogonality.
- stkni 13y agoI'm a bit rusty but I think if you're going to include the board display function on the same line you'll need to separate with a semi-colon. I'm also going to point out that whilst it looks pretty cool (and it runs very fast) it's a frikkin nightmare trying to debug someone else's K-code in production. Which is why I don't recommend that anyone learn it.
- beagle3 13y agoHN formatting got the best of me... It was two lines (you can follow the link I gave to see the original version) I'be found I can easily read Arthur's and Stevan's code. K takes a little more discipline (or talent) to be readable than other languages.
- javajosh 13y ago> qn:{[n],/{:[n=#x;,x;,/_f'f x,\:/:(!n)_dvl,/x]}'(f:0 -1 1+/:)@!n} bd:{[p]`0:".Q"p=\:!#p} One of the reasons golf never interested me is because people kept making these totally inscrutable concoctions that you couldn't even take a "squinty eyed look" at. Contrast this with the rhoscript solution: 8 range permutations (with-index (sum) map uniq arg-a with-index (*exploding subtract) map uniq concatenate length) keep-maxes-by Now, overall it's still not exactly straight-forward, but you can at least understand pieces of it right away, and start inferring things. For example, '8 range' probably constructs a range of integers (it does). The other stuff can be broken apart and tested. By contrast that piece of K code seems actively hostile to understanding it.
- beagle3 13y agoIt's just notation. And much like math, it is very powerful, and not effectively verbalized. But just like math, it takes getting used to - and nearly impossible to go back from once you grok it.