Toggle menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

EightQueenProblem/안정원: Difference between revisions

From ZeroWiki
imported>anjw0111
No edit summary
imported>anjw0111
No edit summary
 
(10 intermediate revisions by the same user not shown)
Line 1: Line 1:
[[최다인]] 학우가 단톡에 Javascript가 어쩌고 Eight Queen이 어쩌고 하길래 짜보았습니다.
다른 언어라면 이렇게 쉽게 안되었을 문제인데, 역시 Python입니다 ^ 오 ^
다른 언어라면 이렇게 쉽게 안되었을 문제인데, 역시 Python입니다^ 오 ^


= EightQueenProblem =
# Start Time : 2014. 03. 16. 1:08
# Start Time : 2014. 03. 16. 1:08
# End Time : 2014. 03. 16. 1:24
# End Time : 2014. 03. 16. 1:24


~Python
  from itertools import permutations
  from itertools import permutations
  n = 8
  n = 8
Line 16: Line 17:
       print ''
       print ''
     print ''
     print ''
    break
= EightQueenProblem2 =
~Python
from itertools import permutations
n = 8
cols = range(n)
for vec in permutations(cols):
  if n == len(set(vec[i]+i for i in cols)) == len(set(vec[i]-i for i in cols)):
    print vec
----
[[EightQueenProblem]], [[EightQueenProblem2]], [[안정원]]



Latest revision as of 14:26, 22 March 2014

다른 언어라면 이렇게 쉽게 안되었을 문제인데, 역시 Python입니다 ^ 오 ^

EightQueenProblem

  1. Start Time : 2014. 03. 16. 1:08
  2. End Time : 2014. 03. 16. 1:24
~Python
from itertools import permutations
n = 8
cols = range(n)
for vec in permutations(cols):
  if n == len(set(vec[i]+i for i in cols)) == len(set(vec[i]-i for i in cols)):
    for i in cols:
      for j in cols:
        if vec[i] == j: print ('Q'),
        else: print '#',
      print 
    print 
    break


EightQueenProblem2

~Python
from itertools import permutations
n = 8
cols = range(n)
for vec in permutations(cols):
  if n == len(set(vec[i]+i for i in cols)) == len(set(vec[i]-i for i in cols)):
    print vec

EightQueenProblem, EightQueenProblem2, 안정원