Join Dan Gookin for an in-depth discussion in this video Trying again and eventual success, part of Code Clinic: C.
- As I pondered my initial failure…with the N-Queens program,…I thought about how to fix it.…I believe the approach to check for attacks is sound,…but the method of tracking a queen's attack was wrong.…So I reversed the method.…Instead of setting attacks,…I'd be defensive,…and scan a square for potential attacks from elsewhere.…The key to doing that…is to find a queen's location on the board.…And the key to that is to store the queen's location…specifically as a row-column pair.…Then I thought about a two-dimensional array.…One element for the row, and another for the column.…
Given that, the first element would always be sequential.…Row one through N.…And that's the same values as an element in an array.…So, all that's truly needed is…a one-dimensional array of integers.…Each element gives the queen's column position…for a certain row.…Working with my original code,…I combined the set queen function…with the find square function.…The function takes as an argument…the board array, the current row,…which is where the queen will be set.…
Dan introduces challenges and then provides an overview of his solutions in C. Challenges include topics such as statistical analysis, searching directories for images, and accessing peripheral devices.
Skill Level Beginner
1. Problem One: Exploring Lake Pend Oreille
2. Problem Two: Image Analysis
3. Problem Three: Eight Queens
4. Problem Four: Accessing Peripherals
5. Problem Five: Recursion and Directories
6. Problem Six: Building the Web
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.