Tim explains the backtrack algo really well, and I give him credit for writing the code on the fly instead of having it pre-canned. He is a real programmer's programmer. I am going to follow alone but I want to tweak it a bit and use a RANDOM function to pick the an empty square. And then do a monte carlo simulaton with time lapse to compare. I am going to make my CPU work! Good job.
You could avoid having things like 'range(len(bo[0]))' and 'bo[i][j]' by using the enumerate() function, which takes an iterable (in this case bo) and returns an enumerate object which can be iterated over for index- value pairs. In code you'd write: for i, row in enumerate(bo): for j, val in enumerate(row): if val == 0: return (i, j) It's a very useful function if you need to iterate over both the index and the value at that index.
Thank you so much for this series, I will definitely finish it. I have always been intimidated by algorithms and AI-related topics, but this video helped me become more comfortable with that.
Great video! 9^81 assumes every square has 9 options but every correctly placed number significantly decreases the number of possible numbers. The actual number is surprisingly not as big as you would expect. Nevertheless it is much better to use the backtracking approach.
Mannnnn, You are killing it. Really you are inspiring me to learn programming. Maybe this isn't the vauu thing to learn but I fell that I am learning something. ( Not wasting time ) Thanks a lot
Hi Tim! I'm very exited for this series, i just started out with python and i'm learning a great deal of your videos! i wanted to ask why this dosn't work? i = 100 while True: if len(str(i)) == 1: print(i) break else: i = (i / 2) print(i) i have also tried to set the condition for the while loop to while len(str(i)) > 1:
Wow, me and my classmates were bored at school today, we tried making a sudoku solver, and woah, I didn’t think we would make efficient logic, we actually managed to make logic similar to the backtracking method, only we didn’t have enough skill to be able to code it
9^81 power is 3^162. We know, that 2^20 is a bit bigger than a million, hence 2^40 is a bit bigger than a trillion. Imagine what's left for 3^162. Another way to visualize it is, that 3^2 ~=10. 3^42 is a bit (in percent) bigger than 10^20. 3^162 is a bit (in percent) bigger than the forth power of 3^42. In fact, it's 3^168/729. So we know, that 3^162 ~~ 10^77, so we can safely assume 3^162 has around 78 digits. (Just checked the calculator - it's around 1.966×10^77. Can't believe how close I was). Edit: 9^81 is only if you literally have no digits on the board or rules about how to position them on it.
The magnitude of 9^81 is mind-bogglingly vast, making a trillion seem like a mere drop in the ocean. To put it into perspective, a trillion, which is 10^12, is dwarfed by 9^81, which is an incomprehensible 2*10^77. Just think about that for a moment: 2 followed by 77 zeros. That's an astronomical number that's hard to fathom. To drive the point home, consider this: a trillion times a trillion is "just" 10^24, which is barely a blip on the radar compared to 9^81. As the exponent increases by just 1, the number multiplies by a factor of 10. So, even a million of these trillion-to-the-trillionth-power calculations is a paltry 10^27. Now, imagine multiplying trillions together six times and then multiplying that by a million. That's what it would take to reach 9^81. This number is so unimaginably large that it's comparable to the estimated number of atoms in the universe. Yes, you read that right: the number of atoms in the universe. It's difficult to wrap one's head around just how staggeringly large 9^81 is. Suffice it to say, it's a number that's beyond our comprehension, a true testament to the incomprehensible vastness of mathematics.
why are you writing len(bo) and len(bo)[0] in the for loops when you could just write range(9), sudoku grids are always 9x9 so you shouldn't complicate the code accounting for an impossibility. You're sacrificing readability for no reason.
thks man, i needed this for a homework and i didnt understand how to do it, you saved me man. Keep going with this kind of examples i enjoyed how you teach us. More baktracking examples please, like the 4 queen s chess table .
@@leventegyorgydeak1300 you're stupid, only our own sun is 10^57 already smh, and all of the atoms in body masses in space are a small fraction of all the space dust atoms
@@rafvissersraf do you realise that 10^77 is 10^20 times more than 10^57? that is an insanely huge number, and you have to multiply by that. Maybe 10^77 is not more than the atoms in the universe, but it is 10^80-something
@@TechWithTim Yes, it uses the backtracking algorithm although I modified it slightly. Before running the backtracking algorithm, the program runs a method on the 'Sudoku board' which checks which numbers already appear within each row. The function then returns a 2D array, where each child array corresponds to a row on the Sudoku board and contains the numbers which do not appear within the given row. The program then runs the backtracking algorithm as standard, but rather than potentially checking each number 1-9 for each empty square, it iterates through the numbers which are not already found in the row. This method ensures that time is not wasted checking trivial cases. I wrote it in JS hoping to implement it within a profile/portfolio website for colleges to view.
9^81 is when all the boxes are empty which essentially never happens, about 20 boxes in typical sudoku are filled so we have about 9^60, that's still an ultra-massive number.
12:46 you explain how you are creating the verticle lines but you say horizontal instead. im not that great at python yet so i was trying to understand how the code would create horizontal lines until i finally realized you meant vertical. this was a headache lol
Hey Tim, love your videos! Thanks for making them. What would be the best way to randomly generate a partially solved Sudoku puzzle as an array of lists like you have in this video?
The logic behind 9^81 is terrible. Why didn't you mention all the squares which are actually filled in? I know number like 9^60 is still enormous but since You're talking about the algorithm and efficiency it's quite ignorant to say "i don't know if the math is correct".
lmao wtf are you talking about. We're talking really big numbers there, no need to be bothering with the few squares already filled. the logic behind 9^81 is acctually perfectly fine and you just wanted to post something anniying. congrats
hey man, what keyboard do you use, i cant stand mine. I use wireless Logitech K270 its decent but i am tempted to get a better keyboard with buttons that feel good and a proper space bar , all these space bars on most keyboards are so bloody rattly , i mean u get used to it, but im sure i can find a good keyboard
hey Tim, Thanks for the great tutorial. Im totally new to programming so I guess this is still a little too advanced for me because I'm already having trouble understanding what is you do exactly when defining the print_board function (the range and Len stuff) :(
For i in range(len(bo)) just creates a list which is as long as the amount of rows on the board and the loops over all the items in that list. for example For i in range(2): print(i) would print out 0 and 1.
@@confidential303 Let me take a crack at explaining if u still need it. Parentheses like these work like the ones from math. So it looks at the inner most then works out. So it start at (bo), then it looks at (len(bo)) which gives an answer, 9 in this case. So range(9) then happens. I hope this helped
Wouldn't saving all possible options for the empty positions and then eliminating them one by one be faster? Once there is a single option then we fill in the position. The way I'd do it would involve different steps at first the most efficient option, looking for places a number can already be placed with 100% certainty, if no success then the next step. Like a human (who knows how to play) would play it.
3:31 I'm sorry but I laughed with loud when you said at 9^81 is in the trillions. I'm super rusty at math but I'm sure it's way beyond trillion trillions.
Tim explains the backtrack algo really well, and I give him credit for writing the code on the fly instead of having it pre-canned. He is a real programmer's programmer. I am going to follow alone but I want to tweak it a bit and use a RANDOM function to pick the an empty square. And then do a monte carlo simulaton with time lapse to compare. I am going to make my CPU work! Good job.
By the way, 9^81 is very much above trillions (10^12). In fact, it is nine hundred quinvigintillion
😮
'quinvingintillion' hahahahahhahaha
it is 196627050475552913618075908526912116283103450944214766927315415537966391196809
196627050475552913618075908526912116283103450944214766927315415537966391196809
Pro tip : you can watch series on KaldroStream. I've been using them for watching a lot of movies lately.
Dude I have been struggling to understand backtracking for a long time now. You just made it so simple to understand. Thanks for the video
You could avoid having things like 'range(len(bo[0]))' and 'bo[i][j]' by using the enumerate() function, which takes an iterable (in this case bo) and returns an enumerate object which can be iterated over for index- value pairs. In code you'd write:
for i, row in enumerate(bo):
for j, val in enumerate(row):
if val == 0:
return (i, j)
It's a very useful function if you need to iterate over both the index and the value at that index.
Thank you so much for this series, I will definitely finish it. I have always been intimidated by algorithms and AI-related topics, but this video helped me become more comfortable with that.
Great video! 9^81 assumes every square has 9 options but every correctly placed number significantly decreases the number of possible numbers. The actual number is surprisingly not as big as you would expect. Nevertheless it is much better to use the backtracking approach.
Hey Tim! I'm Brasilian but i love ur videos. I'm starting now at python.
Hey! Glad you like them
@@bulletprooftrading no, the way I said this is because the videos are not in portuguese.
@@bulletprooftrading ow, it was good, I evolved a lot. I`ve been learning Pyside, Pygame, and other tools . Was very cool.
Mannnnn, You are killing it. Really you are inspiring me to learn programming. Maybe this isn't the vauu thing to learn but I fell that I am learning something. ( Not wasting time ) Thanks a lot
Thank you for putting the mistakes in, it helps a new learner like me!
9^81 is way, way more than a value in the trillions. It's 2 x 10^77.
Wtf
Lol
Omg lincoln Im ur big fan
That's like the total number of atom in the universe
2:28 two 8s in one row... seems legit
i was just about to say that lol
MuabYT that’s a column not row
Thing S
Google “column row”. When I was young, I also got that wrong a lot. But if you practice your english will get better.
@@things990 What do you smoke and where can I get some?
@@muabyt7333 I like calling it x y, x for horizontal, y for the vertical
I survived my BSc thanks to this chanell, now it's saving my life in masters, Thank you!
I found your explanation on backtracking really useful!
Just the series I've been looking for man!
Thanku
very interesting. Will be a good series. Thanks Tim.
Tim is my hero!
Hi Tim! I'm very exited for this series, i just started out with python and i'm learning a great deal of your videos!
i wanted to ask why this dosn't work?
i = 100
while True:
if len(str(i)) == 1:
print(i)
break
else:
i = (i / 2)
print(i)
i have also tried to set the condition for the while loop to
while len(str(i)) > 1:
Aha because when you divide you get a float which has a length of 3 because it counts the “.0” . Try checking if i//10 < 1
Great video! keep upload more code using different algorithms :)
For sure !
thanks Tim it's the best one I saw
Wow, me and my classmates were bored at school today, we tried making a sudoku solver, and woah, I didn’t think we would make efficient logic, we actually managed to make logic similar to the backtracking method, only we didn’t have enough skill to be able to code it
Thanks Tim you are the best
You make really awesome and interesting and useful videos sir
Thankss for this amazing tutorial Tim
That was fun. On to the next one. Cool vid. Thx
Looking forward for the next video
9^81 power is 3^162. We know, that 2^20 is a bit bigger than a million, hence 2^40 is a bit bigger than a trillion. Imagine what's left for 3^162. Another way to visualize it is, that 3^2 ~=10. 3^42 is a bit (in percent) bigger than 10^20. 3^162 is a bit (in percent) bigger than the forth power of 3^42. In fact, it's 3^168/729. So we know, that 3^162 ~~ 10^77, so we can safely assume 3^162 has around 78 digits. (Just checked the calculator - it's around 1.966×10^77. Can't believe how close I was).
Edit: 9^81 is only if you literally have no digits on the board or rules about how to position them on it.
You are a genius 👍🏻
The magnitude of 9^81 is mind-bogglingly vast, making a trillion seem like a mere drop in the ocean. To put it into perspective, a trillion, which is 10^12, is dwarfed by 9^81, which is an incomprehensible 2*10^77. Just think about that for a moment: 2 followed by 77 zeros. That's an astronomical number that's hard to fathom.
To drive the point home, consider this: a trillion times a trillion is "just" 10^24, which is barely a blip on the radar compared to 9^81. As the exponent increases by just 1, the number multiplies by a factor of 10. So, even a million of these trillion-to-the-trillionth-power calculations is a paltry 10^27.
Now, imagine multiplying trillions together six times and then multiplying that by a million. That's what it would take to reach 9^81. This number is so unimaginably large that it's comparable to the estimated number of atoms in the universe. Yes, you read that right: the number of atoms in the universe.
It's difficult to wrap one's head around just how staggeringly large 9^81 is. Suffice it to say, it's a number that's beyond our comprehension, a true testament to the incomprehensible vastness of mathematics.
Thank you Tim! I finally understood it! :D
9**81 is actually so high, that I believe that no computer would be ever able to solve it.
The biggest puzzle was foguring out what the top right corner was :D
finally i understand it!! ur the best
Lovely bro !
Thanks a lot for your donations for others.
Nice explanation. One of the clearest videos on the network.
tim is the best
13:17 the "up thing" is called a pipe...
Vertical Bar
Great content! Keep up the work!!
Make a video on algorithms and data types
Thanks, I feel like I understand recursion a little bit better now.
Awesome! Try watching the next video where I implement it
very good now i go to next one
why are you writing len(bo) and len(bo)[0] in the for loops when you could just write range(9), sudoku grids are always 9x9 so you shouldn't complicate the code accounting for an impossibility. You're sacrificing readability for no reason.
yeah
it makes it easier to work with non-traditional sudokus.
Coding starts at 11:27
in the source code provided by, the GUI isn't working in website
9^81 is roughly equivalent to the amount of atoms in the universe to put that into perspective
thks man, i needed this for a homework and i didnt understand how to do it, you saved me man. Keep going with this kind of examples i enjoyed how you teach us.
More baktracking examples please, like the 4 queen s chess table .
Nice, I did something similar in PHP.
”9^81 is probably like in the trillions or something”... not even close lmao
9.something * 10^77 LMAO
it is more than the number of atoms in the observable universe
@@leventegyorgydeak1300 it isnt
@@leventegyorgydeak1300 you're stupid, only our own sun is 10^57 already smh, and all of the atoms in body masses in space are a small fraction of all the space dust atoms
@@rafvissersraf do you realise that 10^77 is 10^20 times more than 10^57? that is an insanely huge number, and you have to multiply by that. Maybe 10^77 is not more than the atoms in the universe, but it is 10^80-something
I tried backtracking by hand... it worked and I got my new best! (2m46s)
This is very strange. Yesterday I finished a sudoku solver- what a wonderful coincidence.
Is it similar to mine?
@@TechWithTim Yes, it uses the backtracking algorithm although I modified it slightly.
Before running the backtracking algorithm, the program runs a method on the 'Sudoku board' which checks which numbers already appear within each row. The function then returns a 2D array, where each child array corresponds to a row on the Sudoku board and contains the numbers which do not appear within the given row.
The program then runs the backtracking algorithm as standard, but rather than potentially checking each number 1-9 for each empty square, it iterates through the numbers which are not already found in the row. This method ensures that time is not wasted checking trivial cases.
I wrote it in JS hoping to implement it within a profile/portfolio website for colleges to view.
At the end, in the last loop it should be `len(bo[i])`, as currently you are looping only over the first row :)
I see what you mean but it’s actually fine. Since we known the length of each row is the same we can do that.
@@TechWithTim true
Thanks Tim.
9^81 is when all the boxes are empty which essentially never happens, about 20 boxes in typical sudoku are filled so we have about 9^60, that's still an ultra-massive number.
Dude, why couldnt you have made this video when I was in uni and smashed my face into my keyboard when my teacher assigned this as hw lol.
Amazing... can you give me a solution to the Ubongo puzzle?
Absolutely amazing of u
Thanks nicely presented.
why in the second for loop is there an [0], wouldn't you want to use [i] ? To refer to the current array?
Is this the best way to make a sudoku board?
12:46 you explain how you are creating the verticle lines but you say horizontal instead. im not that great at python yet so i was trying to understand how the code would create horizontal lines until i finally realized you meant vertical. this was a headache lol
Hey Tim, love your videos! Thanks for making them. What would be the best way to randomly generate a partially solved Sudoku puzzle as an array of lists like you have in this video?
thank you so much Tim for this code and for making us understand so clearly . just coding isn't effective explaining the concept is so great .
which is the best database to work with python?
can you tell me whether you are coding in pycharm?
Amazing video
What if the puzzle given by user is not solvable?
it will be 81^9
Please explain why we use( if i ==08)
Good one !
Thanks so much dude, this code Will be use from Argentina ♥
Hey man Tim how can we type a modulus please answer
Hey, Can we use A* Search to solve Sudoku?
Can you do a video on killer sudokus?
The logic behind 9^81 is terrible. Why didn't you mention all the squares which are actually filled in? I know number like 9^60 is still enormous but since You're talking about the algorithm and efficiency it's quite ignorant to say "i don't know if the math is correct".
lmao wtf are you talking about.
We're talking really big numbers there, no need to be bothering with the few squares already filled.
the logic behind 9^81 is acctually perfectly fine and you just wanted to post something anniying. congrats
hey man, what keyboard do you use, i cant stand mine. I use wireless Logitech K270 its decent but i am tempted to get a better keyboard with buttons that feel good and a proper space bar , all these space bars on most keyboards are so bloody rattly , i mean u get used to it, but im sure i can find a good keyboard
hey Tim,
Thanks for the great tutorial. Im totally new to programming so I guess this is still a little too advanced for me because I'm already having trouble understanding what is you do exactly when defining the print_board function (the range and Len stuff) :(
For i in range(len(bo)) just creates a list which is as long as the amount of rows on the board and the loops over all the items in that list. for example For i in range(2): print(i) would print out 0 and 1.
@@Alan-pi1vn you making it more confusing
@@confidential303 Let me take a crack at explaining if u still need it. Parentheses like these work like the ones from math. So it looks at the inner most then works out. So it start at (bo), then it looks at (len(bo)) which gives an answer, 9 in this case. So range(9) then happens. I hope this helped
I love it
Wouldn't saving all possible options for the empty positions and then eliminating them one by one be faster? Once there is a single option then we fill in the position.
The way I'd do it would involve different steps at first the most efficient option, looking for places a number can already be placed with 100% certainty, if no success then the next step. Like a human (who knows how to play) would play it.
was great. thanks
Theres a video in computerphile about this, i also recommend everyone to watch it.
That video doesn't explain the backtracking as well as this one.
The way he says sudoku doesn’t hit my ear right
thanks.
I am confused about the printBoard() function.. %? Modulous?? what is that?
What application do you use to record your screen and edit it?
I don't understand the line j == 8
I really want to do this in a pandas array. And make a sudoku puxxle creator.
What software did you use to type in the codes?
Can you make the same sudoku solver with tkinter?
I dont understand how for loops work or anything.. also what is print([i][j])
@@Pranav-x8q Why should we do that?
I am in 11th Grade and I need this for my Skilled Work or how thats called in english. In germany we say: "Facharbeit"
3:31 I'm sorry but I laughed with loud when you said at 9^81 is in the trillions. I'm super rusty at math but I'm sure it's way beyond trillion trillions.
Hey can u clear doubt which is isn't there 11 rows( a single line takes one row right?)so how u set logic for printing horizontal lines after 3 row
Can you do a video for 6x6 sudoku instead of 9x9?
The code would be identical except for board[] and the upper limit of the loop increments
Gee i feel silly here , how do u generate the board, i mean the numbers... is this part of the print bo function
imagine having the audacity to dislike free education
Am I the only who spent half an hour figuring out what the solver is and still didn't figure it out.
How does this work
if j == 8:
print(bo[i][j])
else:
print(str(bo[i][j]) + " ", end="")
where did you find sudoku boards ? I'm looking for CSV exportable boards
it's 81 to the power of 9...
Love it.
Still waiting for part two!
th-cam.com/video/lK4N8E6uNr4/w-d-xo.html
Bhai ye rha part 2