C++ Sudoku Solver in 7 minutes using Recursive Backtracking

preview_player
Показать описание
C++ implementation of a Sudoku solver.

We use a recursive backtracking algorithm and the bitset data structure.

SUPPORT ME ⭐
---------------------------------------------------

BE ACTIVE IN MY COMMUNITY 😄
---------------------------------------------------
Рекомендации по теме
Комментарии
Автор

This was very close to a Java programming assignment at my university, going back and looking at the problem again feels refreshing. At the time I remember looking at some bit operations that had optimised peoples algorithms quite heavily and I brushed it off as too complicated for me at the time haha.

Really helpful video.

Bananaa
Автор

you know there a good programmer when you can see eyebags

gravysnake
Автор

“Slap that like button an odd number of times.”. Nice! 😂

luziferius
Автор

This channel is about to 10x, grateful to have found you early. youtube algo is on your side, ride this momentum and pump out the quality content, all the best man.

WysockiD
Автор

Took me 2 min to realize I wasn't looking at Python and was wondering why none it looked right to me..

nicke
Автор

For a much more efficient (but programmer time consuming) approach to solving Sudoku using backtracking, look up Donald Knuth's DLX (dancing links) algorithm. It's a really interesting algorithm that can be used to solve a number of puzzles, and uses a linked "grid."

I'm addicted to solving Sudoku (just not by hand, but algorithmically)... constraint programming is another fun one to try: choco-solver in Java is a great library and it gives you a very nice taste of how constraint programming works, which is something that you could find useful in your code.

vorpal
Автор

When I did this for Codingame, I used a hybrid approach: use rules to solve until you can't, then choose a possible number to insert into a blank and use rules until it solves or breaks.

TheJaguar
Автор

Nice, I wrote a similar sudoku solver a couple days ago and its a really fun problem
would recommend it to others.

Julian-vivl
Автор

Hm... I wrote a sudoku solver over Christmas... took me just less than 3 weeks... but I did do it in Z80 assembler; I was thinking of adding a similar bitmap mechanism across rows, columns and "blocks" but there are only 8 bits in the byte, so that would make doing 9 fiddly ... and I didn't bother doing further work on it as just checking across the locations was fast enough. I generate a lookup table for the cells in the "block" which are not covered by the row and column checks, so it only needs to check 4 cells per block. It now runs on a Z80 emulator _and_ on a RC2014 (real Z80 based retrocomputer). Perhaps I should do a video on how I wrote it.

john_critchley
Автор

Would love to see a video showing the construction of a solver for a 16x16 sudoku. A little more thought is needed as brute force recursion is too slow.

primeprover
Автор

Subbed. Excited to see where this channel will go!

Kornchipzzz
Автор

Took me a second to work out why the Python code looked so bananas.

JustinRiedyk
Автор

finally someone who indents and brackets properly 👍

etmax
Автор

Very nice! I once used the same concept to solve the eight queens puzzle, it was very entertaining! I might try doing it in C++ now that I know bitsets are a thing :P

MatheusAugustoGames
Автор

Amazing video, your coding style is so clean!

qnn
Автор

this a great video. youtube knows it too bc i watched it when it dropped but it just got recommended it to me again.

kasparpoland
Автор

Really enjoy this content, keep it up.

cameronguilbeau
Автор

James, could you do a video showing a formal proof and (hopefully) the intuition behind detecting the start of a cycle in a singly-linked list?

kylefluto
Автор

Had this as an assignment but in Prolog. I remember how the goal was just to program the brute force method and make sure it could solve hard ones in less than 5 minutes, but we could earn extra points if I made it more efficient with heuristics and movement through the board. Everyone was so shocked when I presented my solution and said it could solve all 5 of the given boards in less than a second haha xD Was the most fun assignment I had at uni.

lupomikti
Автор

I never heard of recursive backtracking before. I'd write a sudoku solver like this: loop over every square, for each of them find all possible solutions. If there's just one solution, fill it in, else don't do anything. Repeat until there are no squares left

laurinneff