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.
@BigFatSandwitch4 жыл бұрын
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
@oneeyedjack24045 жыл бұрын
By the way, 9^81 is very much above trillions (10^12). In fact, it is nine hundred quinvigintillion
@TechWithTim5 жыл бұрын
😮
@yashkhurana91705 жыл бұрын
'quinvingintillion' hahahahahhahaha
@WWFYMN4 жыл бұрын
it is 196627050475552913618075908526912116283103450944214766927315415537966391196809
Pro tip : you can watch series on KaldroStream. I've been using them for watching a lot of movies lately.
@user-hd6xc1xn9d4 жыл бұрын
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.
@ninesquared814 жыл бұрын
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.
@Plengueiraa5 жыл бұрын
Hey Tim! I'm Brasilian but i love ur videos. I'm starting now at python.
@TechWithTim5 жыл бұрын
Hey! Glad you like them
@Plengueiraa4 жыл бұрын
@@bulletprooftrading no, the way I said this is because the videos are not in portuguese.
@Plengueiraa4 жыл бұрын
@@bulletprooftrading ow, it was good, I evolved a lot. I`ve been learning Pyside, Pygame, and other tools . Was very cool.
@ramizquliyev3943 жыл бұрын
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
@melbbb56732 жыл бұрын
Thank you for putting the mistakes in, it helps a new learner like me!
@Krie7ananas3 жыл бұрын
I survived my BSc thanks to this chanell, now it's saving my life in masters, Thank you!
@dylanroberts62174 жыл бұрын
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.
@zaidabraham73104 жыл бұрын
9^81 is way, way more than a value in the trillions. It's 2 x 10^77.
@ThatControlUser3 жыл бұрын
Wtf
@zombiekiller71013 жыл бұрын
Lol
@gamerzgodtawan6882 жыл бұрын
Omg lincoln Im ur big fan
@leftenanalim9 ай бұрын
That's like the total number of atom in the universe
@muabyt73335 жыл бұрын
2:28 two 8s in one row... seems legit
@Rej-dx8um4 жыл бұрын
i was just about to say that lol
@things9904 жыл бұрын
MuabYT that’s a column not row
@muabyt73334 жыл бұрын
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.
@chantelsopio58264 жыл бұрын
@@things990 What do you smoke and where can I get some?
@infinite_xiao54833 жыл бұрын
@@muabyt7333 I like calling it x y, x for horizontal, y for the vertical
@LawZist5 жыл бұрын
Great video! keep upload more code using different algorithms :)
@TechWithTim5 жыл бұрын
For sure !
@officesuperhero96115 жыл бұрын
very interesting. Will be a good series. Thanks Tim.
@flamexc Жыл бұрын
I found your explanation on backtracking really useful!
@castormann4 жыл бұрын
”9^81 is probably like in the trillions or something”... not even close lmao
@VivekYadav-ds8oz4 жыл бұрын
9.something * 10^77 LMAO
@leventegyorgydeak13004 жыл бұрын
it is more than the number of atoms in the observable universe
@ongp7934 жыл бұрын
@@leventegyorgydeak1300 it isnt
@rafvissersraf4 жыл бұрын
@@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
@leventegyorgydeak13004 жыл бұрын
@@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
@estevanmaidaa82135 жыл бұрын
thanks Tim it's the best one I saw
@matthewferguson83692 жыл бұрын
why in the second for loop is there an [0], wouldn't you want to use [i] ? To refer to the current array?
@42mix225 жыл бұрын
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
@mortenb3606 Жыл бұрын
Just the series I've been looking for man! Thanku
@pragyan3945 жыл бұрын
Thanks, I feel like I understand recursion a little bit better now.
@TechWithTim5 жыл бұрын
Awesome! Try watching the next video where I implement it
@avvn93315 жыл бұрын
You make really awesome and interesting and useful videos sir
@sebastiannrregaard58495 жыл бұрын
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:
@TechWithTim5 жыл бұрын
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
@сойка-и8й5 жыл бұрын
Thanks Tim you are the best
@diego567804 жыл бұрын
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 .
@adithyasapalya6345 күн бұрын
in the source code provided by, the GUI isn't working in website
@mehdiSupp5 жыл бұрын
Looking forward for the next video
@stuartjacobs5 жыл бұрын
That was fun. On to the next one. Cool vid. Thx
@adityad89298 ай бұрын
Thankss for this amazing tutorial Tim
@repudiation2305 жыл бұрын
This is very strange. Yesterday I finished a sudoku solver- what a wonderful coincidence.
@TechWithTim5 жыл бұрын
Is it similar to mine?
@repudiation2305 жыл бұрын
@@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.
@robertr7923 Жыл бұрын
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.
@rock533553 жыл бұрын
Thank you Tim! I finally understood it! :D
@poojasrinivasan27274 жыл бұрын
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 .
@ThePzr4 жыл бұрын
Lovely bro ! Thanks a lot for your donations for others.
@BorrowedAtoms4 жыл бұрын
The biggest puzzle was foguring out what the top right corner was :D
@yassernadir29475 жыл бұрын
You are a genius 👍🏻
@user-hd6xc1xn9d4 жыл бұрын
I am confused about the printBoard() function.. %? Modulous?? what is that?
@220SouthlandAve4 ай бұрын
Tim is my hero!
@pratyushvatsa74903 жыл бұрын
What if the puzzle given by user is not solvable?
@adithyadshenoi26684 жыл бұрын
How does this work if j == 8: print(bo[i][j]) else: print(str(bo[i][j]) + " ", end="")
@a.m20533 жыл бұрын
Nice explanation. One of the clearest videos on the network.
@Uriakatos3 жыл бұрын
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.
@mathisalwaysright4048 Жыл бұрын
9**81 is actually so high, that I believe that no computer would be ever able to solve it.
@TriThucMoiNqk3 жыл бұрын
RecursionError: maximum recursion depth exceeded while calling a Python object! help me
@androsio7ja8653 жыл бұрын
finally i understand it!! ur the best
@shockbladezed23523 жыл бұрын
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.
@willforrhall2 жыл бұрын
Make a video on algorithms and data types
@AlexWardi4 жыл бұрын
13:17 the "up thing" is called a pipe...
@aditgaur15854 жыл бұрын
Vertical Bar
@abhisheksarkar48973 жыл бұрын
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
@captaincodm75274 жыл бұрын
Hey man Tim how can we type a modulus please answer
@PetersFXfilms4 жыл бұрын
3:25 "9^81 is probably in the trillions" I facepalmed to hard at that. Come on Tim.
@user-hd6xc1xn9d4 жыл бұрын
I dont understand how for loops work or anything.. also what is print([i][j])
@krisikris73164 жыл бұрын
@@user-mv9iy5ph1f Why should we do that?
@moesparc2 жыл бұрын
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
@solve642 жыл бұрын
Nice, I did something similar in PHP.
@pranav24232 жыл бұрын
How might you analyze the runtime/spacetime of this? I see n^2 work done and then there's a recursive call, but I'm not sure how the recurrence relation would look.
@trenttagestad52824 жыл бұрын
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?
@CollosalTrollge3 жыл бұрын
Gee i feel silly here , how do u generate the board, i mean the numbers... is this part of the print bo function
@rylan80923 жыл бұрын
Great content! Keep up the work!!
@CollosalTrollge3 жыл бұрын
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
@gniewo64 жыл бұрын
very good now i go to next one
@siddhantagarwal68853 жыл бұрын
hi just wanted to understand how will it be 9 raise to the power 81 possibilities , i think there will be only 729 possibilities right ?
@kubogi4 жыл бұрын
I tried backtracking by hand... it worked and I got my new best! (2m46s)
@pallepuaruna69704 жыл бұрын
Absolutely amazing of u
@donaldokorejior19813 жыл бұрын
Would it be fair to say the print(board[ i ][ j ]) prints the last number in the row, but unlike the previously printed numbers, the last number printed is not a string?
@donaldokorejior19813 жыл бұрын
Pleaseeeee any response would help my understanding. I’m new to coding
@peterball32894 жыл бұрын
Thanks nicely presented.
@paclifac77305 жыл бұрын
Thanks so much dude, this code Will be use from Argentina ♥
@vatarants3 жыл бұрын
if j == 8: print(boardfunc[i][j]) what does this line do?
@pragyachamoli61883 жыл бұрын
Hey the source code link isn't working, it says : no input file...?? What do i do
@jakubucinski5 жыл бұрын
Good one !
@yididyakediryasin28862 жыл бұрын
Hey, Can we use A* Search to solve Sudoku?
@maxwellhouse8inator2 жыл бұрын
9^81 is roughly equivalent to the amount of atoms in the universe to put that into perspective
@lazar870223 жыл бұрын
how does one return the grid when its solved instead of returning True/False values ?
@maava4 жыл бұрын
What would the 6x6 box loop look like? Having troubles with it
@anaiscarrichon64094 жыл бұрын
where did you find sudoku boards ? I'm looking for CSV exportable boards
@mpricop5 жыл бұрын
At the end, in the last loop it should be `len(bo[i])`, as currently you are looping only over the first row :)
@TechWithTim5 жыл бұрын
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.
@mpricop5 жыл бұрын
@@TechWithTim true
@ramlabasharat43344 жыл бұрын
Amazing... can you give me a solution to the Ubongo puzzle?
@TheUndulyNoted4 жыл бұрын
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.
@AlexandrBorschchev4 жыл бұрын
yeah
@somebody90334 жыл бұрын
it makes it easier to work with non-traditional sudokus.
@uguree3 жыл бұрын
Isn't it the possibility like for each row and column multiplication of factorials but subtracting given number of numbers for each row column like 1row and 1column let's say4 numbers given for first row so (9-4)! And for first column 2 given number so (9-2)! And for first cubic let's say 3 numbers given we can consider that tooo like (9-3)! But not all individually a correlation of these 3.. row, column and 3x3 matrix.. maybe that algorithm could be faster??
@CastleChuck3 жыл бұрын
I dunno what i've done but for some reason it is only printing the line of the grid underneath the horizontal lines that the if's draw in 😂(they are at the right point so thats a win) 😂 I have copied everything done in the video and not to sure what to try in order to get it to print all the rows from the board. Any ideas?
@Munax.3 жыл бұрын
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.
@marshalljamieson2312 жыл бұрын
The way he says sudoku doesn’t hit my ear right
@jalenthomas23374 жыл бұрын
Hey, I am trying this myself but I am getting nameerror: global name end is not defined or syntax errors with print(" | ", end=""). Any suggestions why that is happening?
@keejay981954 жыл бұрын
Which python version are you using?
@jalenthomas23374 жыл бұрын
Bronko Python 3
@keejay981954 жыл бұрын
@@jalenthomas2337 msg me on discord if you still need help vecom#6091
@DOGChels4 жыл бұрын
What did you do to fix it? I'm having the same issue
@WarlikeSRK4 жыл бұрын
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) :(
@Alan-pi1vn4 жыл бұрын
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.
@confidential3034 жыл бұрын
@@Alan-pi1vn you making it more confusing
@AI-DM3 жыл бұрын
@@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
@roshanloke94234 жыл бұрын
Please explain why we use( if i ==08)
@David-gr9nr3 жыл бұрын
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.
@sora64304 жыл бұрын
which is the best database to work with python?
@brucebane74014 жыл бұрын
tim is the best
@sankethb.k6425 жыл бұрын
I love it
@sarvanik48023 жыл бұрын
can you tell me whether you are coding in pycharm?
@davideettori32265 жыл бұрын
Amazing video
@Sahilblogs5364 жыл бұрын
Hello i am getting an error please help there is no output after implementation of the code
@TheFyrokai3 жыл бұрын
I am a bit confused about how the system knows that we are referring to board when we put a def of print_board(bo) does bo == board? How does the system know? I thought we need to put print_board(board) rather than (bo) Anyone can help to explain?
@dr72553 жыл бұрын
Perhaps I missed something, he doesn't (according to my eyes) print_board(bo) ever. The function says print_board(bo) as the argument to set up the function, but at the end of it he never types in print_board(bo) for the function to run.
@siamahmed82873 жыл бұрын
What application do you use to record your screen and edit it?
@modaryaghi4 жыл бұрын
Thanks Tim.
@just_an_ordinary_being Жыл бұрын
What software did you use to type in the codes?
@adriandiaz10723 жыл бұрын
Is this the best way to make a sudoku board?
@domingo29774 жыл бұрын
dude i copied the gui thing you made on your website & it did not appear when i ran it