Skip to content

Comment on N-queen puzzle in 4 lines of Scalaparent

Comments

I tried to make that a little more readable, and converted it to py3 -- This one produces the same output with python3, as your one-liner with python2:

  #!/usr/bin/env python3

  from itertools import permutations as p

  for vec in p(range(8)):
    if 8 == len(set(vec[i]+i for i in range(8))) \
         == len(set(vec[i]-i for i in range(8))):
      print("\n".join( '.' * i + 'Q' + '.' * (8-i-1) for i in vec),
            end="\n===\n")
The string construction could/should probably also be refactored a bit, but at least this version I have a hope of following the logic... :-)
AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.