No Description

NQueen.nb 24KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536
  1. (* Content-type: application/vnd.wolfram.mathematica *)
  2. (*** Wolfram Notebook File ***)
  3. (* http://www.wolfram.com/nb *)
  4. (* CreatedBy='Mathematica 9.0' *)
  5. (*CacheID: 234*)
  6. (* Internal cache information:
  7. NotebookFileLineBreakTest
  8. NotebookFileLineBreakTest
  9. NotebookDataPosition[ 157, 7]
  10. NotebookDataLength[ 23592, 526]
  11. NotebookOptionsPosition[ 23059, 504]
  12. NotebookOutlinePosition[ 23414, 520]
  13. CellTagsIndexPosition[ 23371, 517]
  14. WindowFrame->Normal*)
  15. (* Beginning of Notebook Content *)
  16. Notebook[{
  17. Cell[CellGroupData[{
  18. Cell[BoxData[{
  19. RowBox[{"n", " ", "=", " ", "6"}], "\[IndentingNewLine]",
  20. RowBox[{"q", " ", "=", " ", "0"}], "\[IndentingNewLine]",
  21. RowBox[{"row", " ", "=", " ", "1"}], "\[IndentingNewLine]",
  22. RowBox[{"board", " ", "=", " ",
  23. RowBox[{"Array", "[",
  24. RowBox[{
  25. RowBox[{"0", "&"}], ",",
  26. RowBox[{"{",
  27. RowBox[{"n", ",", "n"}], "}"}]}], "]"}]}], "\[IndentingNewLine]",
  28. StyleBox[
  29. RowBox[{
  30. RowBox[{
  31. RowBox[{"addQueen", "[",
  32. RowBox[{"x_", ",", " ", "y_"}], "]"}], " ", ":=", "\[IndentingNewLine]",
  33. RowBox[{"If", "[",
  34. RowBox[{
  35. RowBox[{
  36. RowBox[{"board", "[",
  37. RowBox[{"[",
  38. RowBox[{"x", ",", "y"}], "]"}], "]"}], " ", "\[Equal]", " ", "0"}],
  39. ",", " ", "\[IndentingNewLine]",
  40. RowBox[{
  41. RowBox[{"For", "[",
  42. RowBox[{
  43. RowBox[{"i", "=", "1"}], ",", " ",
  44. RowBox[{"i", " ", "\[LessEqual]", " ", "n"}], ",", " ",
  45. RowBox[{"i", "++"}], ",", "\[IndentingNewLine]", "\t",
  46. RowBox[{
  47. RowBox[{
  48. RowBox[{"board", "[",
  49. RowBox[{"[",
  50. RowBox[{"x", ",", "i"}], "]"}], "]"}], "++"}], ";",
  51. "\[IndentingNewLine]", "\t",
  52. RowBox[{
  53. RowBox[{"board", "[",
  54. RowBox[{"[",
  55. RowBox[{"i", ",", "y"}], "]"}], "]"}], "++"}], ";"}]}], "]"}],
  56. ";", "\[IndentingNewLine]", "\t",
  57. RowBox[{"addDiag1", "[",
  58. RowBox[{"x", ",", "y"}], "]"}], ";", "\[IndentingNewLine]", "\t",
  59. RowBox[{"addDiag2", "[",
  60. RowBox[{"x", ",", "y"}], "]"}], ";", "\[IndentingNewLine]", "\t",
  61. RowBox[{
  62. RowBox[{"board", "[",
  63. RowBox[{"[",
  64. RowBox[{"x", ",", "y"}], "]"}], "]"}], "=", "5"}], ";",
  65. "\[IndentingNewLine]", "\t",
  66. RowBox[{"q", "++"}], ";"}]}], "]"}]}], "\[IndentingNewLine]"}],
  67. FontWeight->"Plain"], "\[IndentingNewLine]",
  68. StyleBox[
  69. RowBox[{
  70. RowBox[{"removeQueen", "[",
  71. RowBox[{"x_", ",", " ", "y_"}], "]"}], " ", ":=", "\[IndentingNewLine]",
  72. RowBox[{"If", "[",
  73. RowBox[{
  74. RowBox[{
  75. RowBox[{"board", "[",
  76. RowBox[{"[",
  77. RowBox[{"x", ",", "y"}], "]"}], "]"}], " ", "\[Equal]", " ", "0"}],
  78. ",", " ", "\[IndentingNewLine]",
  79. RowBox[{
  80. RowBox[{"For", "[",
  81. RowBox[{
  82. RowBox[{"i", "=", "1"}], ",", " ",
  83. RowBox[{"i", " ", "\[LessEqual]", " ", "n"}], ",", " ",
  84. RowBox[{"i", "++"}], ",", "\[IndentingNewLine]", "\t",
  85. RowBox[{
  86. RowBox[{
  87. RowBox[{"board", "[",
  88. RowBox[{"[",
  89. RowBox[{"x", ",", "i"}], "]"}], "]"}], "--"}], ";",
  90. "\[IndentingNewLine]", "\t",
  91. RowBox[{
  92. RowBox[{"board", "[",
  93. RowBox[{"[",
  94. RowBox[{"i", ",", "y"}], "]"}], "]"}], "--"}], ";"}]}], "]"}],
  95. ";", "\[IndentingNewLine]", "\t",
  96. RowBox[{"removeDiag1", "[",
  97. RowBox[{"x", ",", "y"}], "]"}], ";", "\[IndentingNewLine]", "\t",
  98. RowBox[{"removeDiag2", "[",
  99. RowBox[{"x", ",", "y"}], "]"}], ";", "\[IndentingNewLine]", "\t",
  100. RowBox[{
  101. RowBox[{"board", "[",
  102. RowBox[{"[",
  103. RowBox[{"x", ",", "y"}], "]"}], "]"}], "=", "0"}], ";",
  104. "\[IndentingNewLine]", "\t",
  105. RowBox[{"q", "--"}], ";"}]}], "]"}]}],
  106. FontWeight->"Plain"]}], "Input",
  107. CellChangeTimes->{{3.614086821784018*^9, 3.6140868795392036`*^9}, {
  108. 3.614086945476557*^9, 3.614086970717807*^9}, {3.61408703324579*^9,
  109. 3.6140870349245043`*^9}, 3.614087130081169*^9, {3.614087317095318*^9,
  110. 3.6140873272137947`*^9}, {3.6140886413500223`*^9, 3.614088651038863*^9}, {
  111. 3.6140902250010433`*^9, 3.6140902332955103`*^9}, 3.614090509191803*^9, {
  112. 3.614093125135645*^9, 3.614093125270405*^9}, {3.614228606199759*^9,
  113. 3.614228617023769*^9}, {3.614228931889865*^9, 3.614228932492371*^9}, {
  114. 3.61427384631563*^9, 3.614273849608101*^9}, 3.6142748615725193`*^9, {
  115. 3.6142749495022507`*^9, 3.614274950708486*^9}, {3.614274999534811*^9,
  116. 3.614275001013351*^9}, {3.614295935721984*^9, 3.614295936287813*^9}, {
  117. 3.6142965206318483`*^9, 3.614296525264701*^9}, {3.614296734051941*^9,
  118. 3.614296777244946*^9}, {3.614297004580608*^9, 3.614297015943162*^9}, {
  119. 3.614297077007979*^9, 3.614297117624159*^9}, {3.615003933618802*^9,
  120. 3.615003952051154*^9}, {3.6151062543706408`*^9, 3.6151062544402933`*^9}, {
  121. 3.6151074422815313`*^9, 3.6151074474558573`*^9}, {3.615107912312002*^9,
  122. 3.615107912348734*^9}, {3.6151851034876432`*^9, 3.6151851039492817`*^9}, {
  123. 3.615190011619216*^9, 3.6151900134082203`*^9}, {3.6151901948792753`*^9,
  124. 3.6151901966209927`*^9}, {3.615190247737862*^9, 3.615190277447234*^9}, {
  125. 3.615190332812373*^9, 3.615190337536715*^9}, {3.615190379501601*^9,
  126. 3.6151903819955*^9}, {3.615190436270568*^9, 3.615190461651951*^9}, {
  127. 3.615190658485202*^9, 3.6151906613615026`*^9}, {3.6151916388089323`*^9,
  128. 3.6151916389877367`*^9}, {3.615261478266347*^9, 3.615261480128601*^9}, {
  129. 3.61526230964149*^9, 3.615262310926528*^9}, 3.615262474556699*^9,
  130. 3.6152625328141727`*^9, {3.615263156432143*^9, 3.6152631565493517`*^9}, {
  131. 3.615264505203335*^9, 3.615264505345048*^9}, {3.615332422765072*^9,
  132. 3.615332422858425*^9}}],
  133. Cell[BoxData["6"], "Output",
  134. CellChangeTimes->{{3.615106255367724*^9, 3.615106283906912*^9},
  135. 3.615106968428494*^9, 3.61510744863015*^9, 3.615107478746314*^9, {
  136. 3.6151079135471983`*^9, 3.615107930917906*^9}, {3.615185105338943*^9,
  137. 3.615185125037609*^9}, {3.615190013761879*^9, 3.615190034928678*^9},
  138. 3.615190197197116*^9, {3.61519024923402*^9, 3.615190277880322*^9},
  139. 3.6151903383804197`*^9, 3.615190382662181*^9, {3.615190437128523*^9,
  140. 3.615190462482052*^9}, 3.6151906618319387`*^9, 3.615191640005769*^9,
  141. 3.615191827602933*^9, 3.6152614828581867`*^9, 3.615262311931246*^9,
  142. 3.615262475092123*^9, 3.615262533476719*^9, 3.615262624286779*^9,
  143. 3.61526266205786*^9, 3.6152627385635967`*^9, 3.61526315707622*^9,
  144. 3.61526322756689*^9, 3.615264507769841*^9, 3.61526459071174*^9,
  145. 3.615332423734779*^9, 3.615333377784543*^9}],
  146. Cell[BoxData["0"], "Output",
  147. CellChangeTimes->{{3.615106255367724*^9, 3.615106283906912*^9},
  148. 3.615106968428494*^9, 3.61510744863015*^9, 3.615107478746314*^9, {
  149. 3.6151079135471983`*^9, 3.615107930917906*^9}, {3.615185105338943*^9,
  150. 3.615185125037609*^9}, {3.615190013761879*^9, 3.615190034928678*^9},
  151. 3.615190197197116*^9, {3.61519024923402*^9, 3.615190277880322*^9},
  152. 3.6151903383804197`*^9, 3.615190382662181*^9, {3.615190437128523*^9,
  153. 3.615190462482052*^9}, 3.6151906618319387`*^9, 3.615191640005769*^9,
  154. 3.615191827602933*^9, 3.6152614828581867`*^9, 3.615262311931246*^9,
  155. 3.615262475092123*^9, 3.615262533476719*^9, 3.615262624286779*^9,
  156. 3.61526266205786*^9, 3.6152627385635967`*^9, 3.61526315707622*^9,
  157. 3.61526322756689*^9, 3.615264507769841*^9, 3.61526459071174*^9,
  158. 3.615332423734779*^9, 3.615333377789864*^9}],
  159. Cell[BoxData["1"], "Output",
  160. CellChangeTimes->{{3.615106255367724*^9, 3.615106283906912*^9},
  161. 3.615106968428494*^9, 3.61510744863015*^9, 3.615107478746314*^9, {
  162. 3.6151079135471983`*^9, 3.615107930917906*^9}, {3.615185105338943*^9,
  163. 3.615185125037609*^9}, {3.615190013761879*^9, 3.615190034928678*^9},
  164. 3.615190197197116*^9, {3.61519024923402*^9, 3.615190277880322*^9},
  165. 3.6151903383804197`*^9, 3.615190382662181*^9, {3.615190437128523*^9,
  166. 3.615190462482052*^9}, 3.6151906618319387`*^9, 3.615191640005769*^9,
  167. 3.615191827602933*^9, 3.6152614828581867`*^9, 3.615262311931246*^9,
  168. 3.615262475092123*^9, 3.615262533476719*^9, 3.615262624286779*^9,
  169. 3.61526266205786*^9, 3.6152627385635967`*^9, 3.61526315707622*^9,
  170. 3.61526322756689*^9, 3.615264507769841*^9, 3.61526459071174*^9,
  171. 3.615332423734779*^9, 3.615333377793964*^9}],
  172. Cell[BoxData[
  173. RowBox[{"{",
  174. RowBox[{
  175. RowBox[{"{",
  176. RowBox[{"0", ",", "0", ",", "0", ",", "0", ",", "0", ",", "0"}], "}"}],
  177. ",",
  178. RowBox[{"{",
  179. RowBox[{"0", ",", "0", ",", "0", ",", "0", ",", "0", ",", "0"}], "}"}],
  180. ",",
  181. RowBox[{"{",
  182. RowBox[{"0", ",", "0", ",", "0", ",", "0", ",", "0", ",", "0"}], "}"}],
  183. ",",
  184. RowBox[{"{",
  185. RowBox[{"0", ",", "0", ",", "0", ",", "0", ",", "0", ",", "0"}], "}"}],
  186. ",",
  187. RowBox[{"{",
  188. RowBox[{"0", ",", "0", ",", "0", ",", "0", ",", "0", ",", "0"}], "}"}],
  189. ",",
  190. RowBox[{"{",
  191. RowBox[{"0", ",", "0", ",", "0", ",", "0", ",", "0", ",", "0"}], "}"}]}],
  192. "}"}]], "Output",
  193. CellChangeTimes->{{3.615106255367724*^9, 3.615106283906912*^9},
  194. 3.615106968428494*^9, 3.61510744863015*^9, 3.615107478746314*^9, {
  195. 3.6151079135471983`*^9, 3.615107930917906*^9}, {3.615185105338943*^9,
  196. 3.615185125037609*^9}, {3.615190013761879*^9, 3.615190034928678*^9},
  197. 3.615190197197116*^9, {3.61519024923402*^9, 3.615190277880322*^9},
  198. 3.6151903383804197`*^9, 3.615190382662181*^9, {3.615190437128523*^9,
  199. 3.615190462482052*^9}, 3.6151906618319387`*^9, 3.615191640005769*^9,
  200. 3.615191827602933*^9, 3.6152614828581867`*^9, 3.615262311931246*^9,
  201. 3.615262475092123*^9, 3.615262533476719*^9, 3.615262624286779*^9,
  202. 3.61526266205786*^9, 3.6152627385635967`*^9, 3.61526315707622*^9,
  203. 3.61526322756689*^9, 3.615264507769841*^9, 3.61526459071174*^9,
  204. 3.615332423734779*^9, 3.615333377798595*^9}]
  205. }, Open ]],
  206. Cell[BoxData[
  207. RowBox[{"\[IndentingNewLine]",
  208. RowBox[{
  209. RowBox[{
  210. RowBox[{"addDiag1", "[",
  211. RowBox[{"x0_", ",", "y0_"}], "]"}], " ", ":=", "\[IndentingNewLine]",
  212. RowBox[{"Module", "[",
  213. RowBox[{
  214. RowBox[{"{",
  215. RowBox[{
  216. RowBox[{"x", " ", "=", " ", "x0"}], ",",
  217. RowBox[{"y", " ", "=", " ", "y0"}]}], "}"}], ",",
  218. "\[IndentingNewLine]",
  219. RowBox[{
  220. RowBox[{"While", "[",
  221. RowBox[{
  222. RowBox[{
  223. RowBox[{"x", "\[NotEqual]", "1"}], "&&",
  224. RowBox[{"y", "\[NotEqual]", "1"}]}], ",", "\[IndentingNewLine]",
  225. "\t",
  226. RowBox[{
  227. RowBox[{"x", "--"}], ";", "\[IndentingNewLine]", "\t",
  228. RowBox[{"y", "--"}]}]}], "]"}], ";", "\[IndentingNewLine]",
  229. RowBox[{"While", "[",
  230. RowBox[{
  231. RowBox[{
  232. RowBox[{"x", "\[NotEqual]",
  233. RowBox[{"n", "+", "1"}]}], "&&",
  234. RowBox[{"y", "\[NotEqual]",
  235. RowBox[{"n", "+", "1"}]}]}], ",", "\[IndentingNewLine]", "\t",
  236. RowBox[{
  237. RowBox[{
  238. RowBox[{"board", "[",
  239. RowBox[{"[",
  240. RowBox[{"x", ",", "y"}], "]"}], "]"}], "++"}], ";",
  241. "\[IndentingNewLine]", "\t",
  242. RowBox[{"x", "++"}], ";", "\[IndentingNewLine]", "\t",
  243. RowBox[{"y", "++"}], ";"}]}], "]"}]}]}], "]"}]}],
  244. "\[IndentingNewLine]", "\[IndentingNewLine]",
  245. RowBox[{
  246. RowBox[{"addDiag2", "[",
  247. RowBox[{"x0_", ",", "y0_"}], "]"}], " ", ":=", "\[IndentingNewLine]",
  248. RowBox[{"Module", "[",
  249. RowBox[{
  250. RowBox[{"{",
  251. RowBox[{
  252. RowBox[{"x", " ", "=", " ", "x0"}], ",", " ",
  253. RowBox[{"y", " ", "=", " ", "y0"}]}], "}"}], ",",
  254. "\[IndentingNewLine]",
  255. RowBox[{
  256. RowBox[{"While", "[",
  257. RowBox[{
  258. RowBox[{
  259. RowBox[{"x", " ", "\[NotEqual]", "1"}], " ", "&&", " ",
  260. RowBox[{"y", " ", "\[NotEqual]", " ", "n"}]}], ",",
  261. "\[IndentingNewLine]", "\t",
  262. RowBox[{
  263. RowBox[{"x", "--"}], ";", "\[IndentingNewLine]", "\t",
  264. RowBox[{"y", "++"}]}]}], "]"}], ";", "\[IndentingNewLine]",
  265. RowBox[{"While", "[",
  266. RowBox[{
  267. RowBox[{
  268. RowBox[{"x", "\[NotEqual]",
  269. RowBox[{"n", "+", "1"}]}], "&&",
  270. RowBox[{"y", "\[NotEqual]", "0"}]}], ",", "\[IndentingNewLine]",
  271. "\t",
  272. RowBox[{
  273. RowBox[{
  274. RowBox[{"board", "[",
  275. RowBox[{"[",
  276. RowBox[{"x", ",", "y"}], "]"}], "]"}], "++"}], ";",
  277. "\[IndentingNewLine]", "\t",
  278. RowBox[{"x", "++"}], ";", "\[IndentingNewLine]", "\t",
  279. RowBox[{"y", "--"}], ";"}]}], "]"}]}]}], "]"}]}],
  280. "\[IndentingNewLine]", "\[IndentingNewLine]",
  281. RowBox[{
  282. RowBox[{"removeDiag1", "[",
  283. RowBox[{"x0_", ",", "y0_"}], "]"}], " ", ":=", "\[IndentingNewLine]",
  284. RowBox[{"Module", "[",
  285. RowBox[{
  286. RowBox[{"{",
  287. RowBox[{
  288. RowBox[{"x", " ", "=", " ", "x0"}], ",",
  289. RowBox[{"y", " ", "=", " ", "y0"}]}], "}"}], ",",
  290. "\[IndentingNewLine]",
  291. RowBox[{
  292. RowBox[{"While", "[",
  293. RowBox[{
  294. RowBox[{
  295. RowBox[{"x", "\[NotEqual]", "1"}], "&&",
  296. RowBox[{"y", "\[NotEqual]", "1"}]}], ",", "\[IndentingNewLine]",
  297. "\t",
  298. RowBox[{
  299. RowBox[{"x", "--"}], ";", "\[IndentingNewLine]", "\t",
  300. RowBox[{"y", "--"}]}]}], "]"}], ";", "\[IndentingNewLine]",
  301. RowBox[{"While", "[",
  302. RowBox[{
  303. RowBox[{
  304. RowBox[{"x", "\[NotEqual]",
  305. RowBox[{"n", "+", "1"}]}], "&&",
  306. RowBox[{"y", "\[NotEqual]",
  307. RowBox[{"n", "+", "1"}]}]}], ",", "\[IndentingNewLine]", "\t",
  308. RowBox[{
  309. RowBox[{
  310. RowBox[{"board", "[",
  311. RowBox[{"[",
  312. RowBox[{"x", ",", "y"}], "]"}], "]"}], "--"}], ";",
  313. "\[IndentingNewLine]", "\t",
  314. RowBox[{"x", "++"}], ";", "\[IndentingNewLine]", "\t",
  315. RowBox[{"y", "++"}], ";"}]}], "]"}]}]}], "]"}]}],
  316. "\[IndentingNewLine]", "\[IndentingNewLine]",
  317. RowBox[{
  318. RowBox[{"removeDiag2", "[",
  319. RowBox[{"x0_", ",", "y0_"}], "]"}], " ", ":=", "\[IndentingNewLine]",
  320. RowBox[{"Module", "[",
  321. RowBox[{
  322. RowBox[{"{",
  323. RowBox[{
  324. RowBox[{"x", " ", "=", " ", "x0"}], ",", " ",
  325. RowBox[{"y", " ", "=", " ", "y0"}]}], "}"}], ",",
  326. "\[IndentingNewLine]",
  327. RowBox[{
  328. RowBox[{"While", "[",
  329. RowBox[{
  330. RowBox[{
  331. RowBox[{"x", " ", "\[NotEqual]", "1"}], " ", "&&", " ",
  332. RowBox[{"y", " ", "\[NotEqual]", " ", "n"}]}], ",",
  333. "\[IndentingNewLine]", "\t",
  334. RowBox[{
  335. RowBox[{"x", "--"}], ";", "\[IndentingNewLine]", "\t",
  336. RowBox[{"y", "++"}]}]}], "]"}], ";", "\[IndentingNewLine]",
  337. RowBox[{"While", "[",
  338. RowBox[{
  339. RowBox[{
  340. RowBox[{"x", "\[NotEqual]",
  341. RowBox[{"n", "+", "1"}]}], "&&",
  342. RowBox[{"y", "\[NotEqual]", "0"}]}], ",", "\[IndentingNewLine]",
  343. "\t",
  344. RowBox[{
  345. RowBox[{
  346. RowBox[{"board", "[",
  347. RowBox[{"[",
  348. RowBox[{"x", ",", "y"}], "]"}], "]"}], "--"}], ";",
  349. "\[IndentingNewLine]", "\t",
  350. RowBox[{"x", "++"}], ";", "\[IndentingNewLine]", "\t",
  351. RowBox[{"y", "--"}], ";"}]}], "]"}]}]}], "]"}]}],
  352. "\[IndentingNewLine]", "\[IndentingNewLine]",
  353. RowBox[{
  354. RowBox[{"solveNQ", "[", "row_", "]"}], " ", ":=", " ",
  355. "\[IndentingNewLine]",
  356. RowBox[{"If", "[",
  357. RowBox[{
  358. RowBox[{"q", " ", "\[Equal]", " ", "n"}], ",", " ",
  359. RowBox[{"Return", " ", "True"}]}], "]"}]}], "\[IndentingNewLine]",
  360. RowBox[{"If", "[",
  361. RowBox[{
  362. RowBox[{"q", " ", "<", " ", "n"}], ",", "\[IndentingNewLine]", "\t",
  363. RowBox[{"For", "[",
  364. RowBox[{
  365. RowBox[{"i", " ", "=", " ", "1"}], ",", " ",
  366. RowBox[{"i", " ", "\[LessEqual]", " ", "n"}], ",", " ",
  367. RowBox[{"i", "++"}], ",", "\[IndentingNewLine]", "\t\t",
  368. RowBox[{"If", "[",
  369. RowBox[{
  370. RowBox[{
  371. RowBox[{"board", "[",
  372. RowBox[{"[",
  373. RowBox[{"row", ",", "i"}], "]"}], "]"}], "\[Equal]", " ", "0"}],
  374. ",", "\[IndentingNewLine]", "\t\t",
  375. RowBox[{
  376. RowBox[{"addQueen", "[",
  377. RowBox[{"row", ",", " ", "i"}], "]"}], ";", "\[IndentingNewLine]",
  378. "\t\t",
  379. RowBox[{"If", "[",
  380. RowBox[{
  381. RowBox[{
  382. RowBox[{"solveNQ", "[",
  383. RowBox[{"row", "+", "1"}], "]"}], " ", "\[Equal]", " ",
  384. "True"}], ",", "\[IndentingNewLine]", "\t\t",
  385. RowBox[{"Return", " ", "True"}], ",", "\[IndentingNewLine]",
  386. "\t\t",
  387. RowBox[{"removeQueen", "[",
  388. RowBox[{"row", ",", " ", "i"}], "]"}]}], "\[IndentingNewLine]",
  389. "]"}]}]}], "]"}]}], "]"}], ",",
  390. RowBox[{"Return", " ", "False"}]}], "]"}], "\[IndentingNewLine]",
  391. "\[IndentingNewLine]"}]}]], "Input",
  392. CellChangeTimes->{{3.6140882860306892`*^9, 3.614088356222574*^9}, {
  393. 3.614088407482459*^9, 3.6140884088398943`*^9}, {3.614088441634379*^9,
  394. 3.6140884423723*^9}, {3.614088490098531*^9, 3.6140885902695923`*^9}, {
  395. 3.6140886960238657`*^9, 3.614088726433132*^9}, 3.614089090947764*^9, {
  396. 3.614089139366663*^9, 3.6140891440108967`*^9}, {3.614089227679269*^9,
  397. 3.614089228765727*^9}, {3.614090051988195*^9, 3.614090063043016*^9}, {
  398. 3.6140900943276653`*^9, 3.614090117715989*^9}, {3.614090204529945*^9,
  399. 3.614090210262413*^9}, {3.614090263360017*^9, 3.61409026573615*^9}, {
  400. 3.614090382564814*^9, 3.614090386051043*^9}, {3.614093879551062*^9,
  401. 3.614093881943919*^9}, {3.614095376704281*^9, 3.614095382549965*^9}, {
  402. 3.6140954633993196`*^9, 3.614095498136191*^9}, {3.614095800754363*^9,
  403. 3.614095827899227*^9}, 3.614096884406939*^9, {3.6140969410146723`*^9,
  404. 3.614096972295486*^9}, {3.6140970611881237`*^9, 3.6140970897774754`*^9}, {
  405. 3.6140983955254307`*^9, 3.6140984016668043`*^9}, {3.614098691252757*^9,
  406. 3.614098711506929*^9}, {3.614098749115408*^9, 3.614098766143446*^9}, {
  407. 3.6141250157128143`*^9, 3.614125020870408*^9}, {3.614125089209598*^9,
  408. 3.6141251139686127`*^9}, {3.614125242684229*^9, 3.6141252524445467`*^9}, {
  409. 3.614225752833281*^9, 3.614225759225267*^9}, {3.614225795674617*^9,
  410. 3.614225803058391*^9}, {3.614228169553487*^9, 3.6142281914864407`*^9}, {
  411. 3.614228262014213*^9, 3.614228444901247*^9}, {3.614296503441597*^9,
  412. 3.6142965153274508`*^9}, {3.614296643570386*^9, 3.614296681054344*^9}, {
  413. 3.614297024104217*^9, 3.6142970681013193`*^9}, {3.6150039036360207`*^9,
  414. 3.6150039275940228`*^9}, {3.6151001122139397`*^9, 3.615100379691326*^9}, {
  415. 3.615100413677575*^9, 3.61510044643744*^9}, {3.615101476187705*^9,
  416. 3.615101552163875*^9}, {3.615101619029747*^9, 3.615101625804593*^9}, {
  417. 3.6151019977748632`*^9, 3.615102007495118*^9}, {3.6151069462614527`*^9,
  418. 3.615106946779744*^9}, 3.615239106664412*^9, 3.615640883087833*^9, {
  419. 3.615640920905452*^9, 3.615640965899955*^9}}],
  420. Cell[BoxData[
  421. RowBox[{"\[IndentingNewLine]",
  422. RowBox[{
  423. RowBox[{"brownBySix", ":=", "\[IndentingNewLine]",
  424. RowBox[{"If", "[",
  425. RowBox[{
  426. RowBox[{
  427. RowBox[{"Mod", "[",
  428. RowBox[{"n", ",", "6"}], "]"}], "\[Equal]", "0"}], ",",
  429. "\[IndentingNewLine]",
  430. RowBox[{"For", "[",
  431. RowBox[{
  432. RowBox[{"u", " ", "=", " ", "1"}], ",", " ",
  433. RowBox[{"u", " ", "\[LessEqual]", " ",
  434. RowBox[{"n", "/", "3"}]}], ",", " ",
  435. RowBox[{"u", "++"}], ",", "\[IndentingNewLine]", "\t",
  436. RowBox[{
  437. RowBox[{"addQueen", "[",
  438. RowBox[{"u", ",",
  439. RowBox[{"3", "u"}]}], "]"}], ";", "\[IndentingNewLine]", "\t",
  440. RowBox[{"addQueen", "[",
  441. RowBox[{
  442. RowBox[{"u", " ", "+", " ",
  443. RowBox[{"n", "/", "3"}]}], ",", " ",
  444. RowBox[{
  445. RowBox[{"3", "u"}], " ", "-", " ", "1"}]}], "]"}], ";",
  446. "\[IndentingNewLine]", "\t",
  447. RowBox[{"addQueen", "[",
  448. RowBox[{
  449. RowBox[{"u", " ", "+", " ",
  450. RowBox[{"2",
  451. RowBox[{"n", "/", "3"}]}]}], ",", " ",
  452. RowBox[{
  453. RowBox[{"3", "u"}], " ", "-", " ", "2"}]}], "]"}]}]}],
  454. "\[IndentingNewLine]", "\t", "]"}]}], "]"}]}], "\[IndentingNewLine]",
  455. "\[IndentingNewLine]"}]}]], "Input",
  456. CellChangeTimes->{{3.614125139338093*^9, 3.614125142875205*^9}, {
  457. 3.6141254166326303`*^9, 3.614125422422567*^9}, 3.6142257085838127`*^9, {
  458. 3.614228452683065*^9, 3.614228456343454*^9}, {3.614228625918419*^9,
  459. 3.614228648486783*^9}, 3.614228974544014*^9, {3.614229034041863*^9,
  460. 3.6142291340188227`*^9}, {3.6142291688925*^9, 3.614229261196371*^9}, {
  461. 3.614229319113182*^9, 3.614229361896606*^9}, {3.614229392723219*^9,
  462. 3.614229400714045*^9}, {3.6142294366931553`*^9, 3.614229501900256*^9},
  463. 3.6142738652163687`*^9, {3.614274102765471*^9, 3.614274221660686*^9}, {
  464. 3.6142744701533337`*^9, 3.6142744787674026`*^9}, {3.6142748408168907`*^9,
  465. 3.614274847336853*^9}, {3.614274878489946*^9, 3.6142748786495523`*^9}, {
  466. 3.61427490975418*^9, 3.614274917106642*^9}, {3.614274961444104*^9,
  467. 3.6142749714043217`*^9}, {3.614295974161104*^9, 3.614295982703451*^9}, {
  468. 3.6142972168331614`*^9, 3.614297255648562*^9}, {3.615106291105151*^9,
  469. 3.61510631177634*^9}, {3.615106369537963*^9, 3.615106369889958*^9}, {
  470. 3.615106880722383*^9, 3.615106884400844*^9}, {3.615106978052498*^9,
  471. 3.6151069794345427`*^9}, {3.615107020380588*^9, 3.615107023339645*^9}, {
  472. 3.615107219467105*^9, 3.615107222689253*^9}, {3.615107336246387*^9,
  473. 3.615107341124178*^9}, {3.615107379175962*^9, 3.615107379661982*^9}, {
  474. 3.615107456561517*^9, 3.615107462247404*^9}, {3.615107522482216*^9,
  475. 3.6151075394581327`*^9}, {3.615107618822316*^9, 3.615107622267558*^9}, {
  476. 3.615185113782856*^9, 3.615185113851839*^9}, {3.6151900259295673`*^9,
  477. 3.6151900477079563`*^9}, {3.615191652847473*^9, 3.615191680955138*^9}, {
  478. 3.6151918108320923`*^9, 3.6151918181906548`*^9}, {3.6151918576333313`*^9,
  479. 3.6151919947074003`*^9}, {3.6151920909747877`*^9, 3.615192109142665*^9}, {
  480. 3.6151921822428083`*^9, 3.615192215769335*^9}, {3.615192264171521*^9,
  481. 3.6151922900195*^9}, {3.615192326296124*^9, 3.6151923753256617`*^9}, {
  482. 3.615192426682247*^9, 3.615192427534871*^9}, {3.615192633710935*^9,
  483. 3.615192641419223*^9}, {3.615261495850395*^9, 3.61526152503197*^9}, {
  484. 3.6152615927075033`*^9, 3.6152617497662697`*^9}, {3.61526178753685*^9,
  485. 3.615261861017095*^9}, {3.615261935275077*^9, 3.6152619675637712`*^9}, {
  486. 3.615262041377157*^9, 3.615262064374447*^9}, {3.615262342951951*^9,
  487. 3.6152624639934397`*^9}, {3.615262617778508*^9, 3.6152626499827623`*^9}, {
  488. 3.615262733504818*^9, 3.615262734172369*^9}, {3.615262789445963*^9,
  489. 3.615262798842525*^9}, {3.615263162798306*^9, 3.615263305983286*^9}, {
  490. 3.615264512347466*^9, 3.615264585091168*^9}, 3.615640892105657*^9, {
  491. 3.615640972797007*^9, 3.61564097643475*^9}}]
  492. },
  493. WindowSize->{983, 947},
  494. WindowMargins->{{Automatic, 133}, {38, Automatic}},
  495. FrontEndVersion->"10.0 for Mac OS X x86 (32-bit, 64-bit Kernel) (June 27, \
  496. 2014)",
  497. StyleDefinitions->"Default.nb"
  498. ]
  499. (* End of Notebook Content *)
  500. (* Internal cache information *)
  501. (*CellTagsOutline
  502. CellTagsIndex->{}
  503. *)
  504. (*CellTagsIndex
  505. CellTagsIndex->{}
  506. *)
  507. (*NotebookFileOutline
  508. Notebook[{
  509. Cell[CellGroupData[{
  510. Cell[579, 22, 5220, 115, 403, "Input"],
  511. Cell[5802, 139, 856, 12, 28, "Output"],
  512. Cell[6661, 153, 856, 12, 28, "Output"],
  513. Cell[7520, 167, 856, 12, 28, "Output"],
  514. Cell[8379, 181, 1498, 32, 28, "Output"]
  515. }, Open ]],
  516. Cell[9892, 216, 9170, 213, 913, "Input"],
  517. Cell[19065, 431, 3990, 71, 182, "Input"]
  518. }
  519. ]
  520. *)
  521. (* End of internal cache information *)