by pathikrit on 4/10/16, 10:41 AM with 94 comments
by dkopi on 4/10/16, 12:16 PM
I find this type of code an anti pattern of how good code should be. This solution has a high "cognitive load" imho: http://chrismm.com/blog/how-to-reduce-the-cognitive-load-of-...
I'd much rather see a 15-20 line solution that's clear and readable, than a 4 line solution that I have to reverse engineer.
by est on 4/10/16, 2:00 PM
_=[__import__('sys').stdout.write("\n".join('.' * i + 'Q' + '.' * (8-i-1) for i in vec) + "\n===\n") for vec in __import__('itertools').permutations(xrange(8)) if 8 == len(set(vec[i]+i for i in xrange(8))) == len(set(vec[i]-i for i in xrange(8)))]
by todd8 on 4/10/16, 6:31 PM
from itertools import permutations
def nQueens(n):
return (p for p in permutations(range(n))
if (len(set(c+d for c,d in enumerate(p))) == n and
len(set(c-d for c,d in enumerate(p))) == n))
for num,solution in enumerate(nQueens(8)):
print("Solution #", num+1)
print("\n".join((" ".join("Q" if i == col else "-" for i in range(8))) for col in solution))
by pkolaczk on 4/10/16, 12:53 PM
by wslh on 4/10/16, 12:55 PM
by SagelyGuru on 4/10/16, 2:20 PM
I am not going to spoil the fun by giving you the details here, just the hint: start on the right square, depending on whether N is even or odd. Then place successive queens in a knight jump pattern.
It is fascinating to me that whoever invented chess a long time ago may have been aware of these subtle complementary relationships between the different types of moves?
by user2994cb on 4/10/16, 6:21 PM
queens n = q n n [[]] where
q 0 m ss = ss
q n m ss = q (n-1) m (concatMap (\s->(map (:s)(filter (f 1 s) [0..m-1]))) ss)
f _ [] a = True
f n (b:s) a = a /= b && a /= b+n && a /= b-n && f (n+1) s a
main = print $ queens 8
by brownbat on 4/10/16, 2:10 PM
http://citeseerx.ist.psu.edu/viewdoc/download;jsessionid=4DC...
by jxy on 4/10/16, 2:38 PM
Rosetta posts should always include a one liner from APL, so here is a link:
by pmorici on 4/10/16, 2:16 PM
by edejong on 4/10/16, 3:51 PM
by dblock on 4/10/16, 3:48 PM
by michaelaiello on 4/10/16, 12:10 PM
by junke on 4/10/16, 2:42 PM
by digsmahler on 4/10/16, 3:06 PM
by master_yoda_1 on 4/10/16, 2:36 PM
#include <nqueensolver.h>
int main(){int n=5;solve(n);}
Please include the binaries for nqueen solver when compiling and running.
The point I am trying to make is that, in such a high label language like scala, this kind of claim sounds foolish.
by Bladtman on 4/10/16, 2:36 PM