From the course: Code Clinic: Ruby
Unlock the full course today
Join today to access over 22,400 courses taught by industry experts or purchase this course individually.
Further exercises
- At its heart the eight queens problem is actually an exercise in efficient algorithm design. If you enjoyed this problem, you can take it even further. Here are some suggestions for further exercises you can attempt on your own. The most common extension of this chalenge is to use a different size chessboard, for example a nine queens challenge would use a nine by nine board with nine queens. Because the number of queens varies and always matches the size of the board these are often referred to as n-queens problems, the number of queens can vary. Some solutions to the eight queens challenge are only effective for an eight by eight board. The solution I've just demonstrated to you will work for any size board, let me show you. Inside our Code Clinic project I've added a new file called n_queens.rb and I've only made one change to this file, which is that instead of just having board.new, like we had in recursion_all or dot new, instead now we're passing in a size. And if you…
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.
Contents
-
-
-
-
-
Eight Queens problem1m 46s
-
Hints, tips, and tricks3m 54s
-
Overview of my solution5m 55s
-
Queen and board classes6m 10s
-
Displaying the board7m 1s
-
Determining safe positions6m 48s
-
Using loops7m 8s
-
Loops with backtracking5m 12s
-
Loops with smarter backtracking6m 2s
-
Recursion primer3m 45s
-
Using recursion6m 52s
-
Finding all possible solutions5m 46s
-
Further exercises3m 56s
-
-
-
-