N Queens

Show all solutions of n-queens.
Output 1302 if queens' positions are [(0, 1), (1, 3), (2, 0), (3, 2)].
One solution per one line.
Solutions should be sorted as string.
4 <= N <= 10

IN

4

OUT

1302
2031

IN

5

OUT

02413
03142
13024
14203
20314
24130
30241
31420
41302
42031

IN

6

OUT

135024
251403
304152
420531

IN

7

OUT

0246135
0362514
0415263
0531642
1306425
1350246
1403625
1420635
1463025
1526304
1642053
2051463
2053164
2461350
2514036
2613504
2630415
3025164
3041526
3164205
3502461
3625140
3641502
4036251
4053162
4152630
4205316
4613502
4615203
5024613
5140362
5203641
5246031
5263041
5316420
5360241
6135024
6251403
6304152
6420531

IN

8

OUT

04752613
05726314
06357142
06471352
13572064
14602753
14630752
15063724
15720364
16257403
16470352
17502463
20647135
24170635
24175360
24603175
24730615
25147063
25160374
25164073
25307461
25317460
25703641
25704613
25713064
26174035
26175304
27360514
30471625
30475261
31475026
31625704
31625740
31640752
31746025
31750246
35041726
35716024
35720641
36074152
36271405
36415027
36420571
37025164
37046152
37420615
40357162
40731625
40752613
41357206
41362750
41506372
41703625
42057136
42061753
42736051
46027531
46031752
46137025
46152037
46152073
46302751
47302516
47306152
50417263
51602473
51603742
52064713
52073164
52074136
52460317
52470316
52613704
52617403
52630714
53047162
53174602
53602417
53607142
57130642
60275314
61307425
61520374
62057413
62714053
63147025
63175024
64205713
71306425
71420635
72051463
73025164


Leave a comment

Parsed as Markdown

Login to leave a comment