From the course: Code Clinic: Swift
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Solution overview
- [Instructor] So let's go over my solution to eight queens. Here's how I approach the problem. First, I want to find all of the horizontal and vertical solutions. From there, I'll search through those solutions and find which one of those have diagonal solutions as well and that represents the final solutions. Once we have the final solutions we simply cycle through those and present those to the user. For solving the horizontal and vertical solutions, I use and array of eight integers for each solution. The index of the array represents the column. And the value of that index represents the row. And every value must be used exactly once. So we take this idea and find all of the permutations. And that gives us all of the horizontal and vertical solutions. So here's what that looks like. So we have a chess board laid out with the columns at zero through seven and the rows at zero through seven, starting from the top left. If every value in the array is unique, then no columns or rows…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.