I ended up here while trying to fix my own version of A* code for a personal project. Although in a completely different language, I figured following the logic from start to finish would help. I am happy to say that after watching this twice, clocking in at a near 2 hours of of the most energetic coding I've ever observed, I realized one of my i's were a j.
I personally hate it when he shows the end result at the beginning. At least give a spoiler warning or a timestamp to skip it. For me, seeing the exact end result removes nearly all motivation to watch through an hour long two-part tutorial. I would rather watch the project organically come together as he builds it, without knowing exactly what to expect.
I know this is a pretty old video, but for anyone watching. The reason it wasnt giving his expected results with no walls and no diagonals is because you need to add tiebreaking in. You can do this simply by changing for (int i = 0; i < openSet.Count; i++) { if (openSet[i].F < openSet[winner].F) winner = i; } Too for (int i = 0; i < openSet.Count; i++) { if (openSet[i].F < openSet[winner].F) winner = i; else if (openSet[i].F == openSet[winner].F)//tie breaking if (openSet[i].H < openSet[winner].H) winner = i; }
Best explanation of A* on the internet! By the way, you could have added neighbours to a spot just before looping through its neighbours. This way if you didn't need to check the neighbours of some spots, you wouldn't need to add neighbours to it. They could just be added to closed set without neighbours. This would save a lot of memory when you're dealing with many spots
Man, thank to you again!! I'm so interesting in algorithms and ML, but didn't know where to start. And your lectures are such a good place to start and go far! It's really great, new level, so different to compare with usual front-end JS, it's real science, it's interesting, it's improve you. Thank you!
Translating this into C# for unity is... interesting. Tough to find a good tutorial on pathfinding, luckily this seems to be working for me so far. Love the videos keep up the great work : )
Interesting how the animation at the beginning looks a bit like the "stepped leader" of a lightning strike. I wonder if this has any bearing on that phenomenon, which I believe isn't that well understood - could be an opportunity for some cross-disciplinary research.... :)
26:35 if splice removes an element in the given index of the array, couldn't you use it as instead of creating the function removeFromArray? Loving the content ❤
What he meant was, to do different languages for educational purposes it's not just about the difficulty, after all this channel is for sharing information about programming.
Hello, thank you for your video. I have implemented the A Star on Android Studio. Can I share it with you ? Have you ever though of making a Robot Localization with particles filter on simulation ? I have implemented it this weekend.
Mimics nature. Question is, is this the absolute pinnacle of pathfinding. What other 'better' ways could there be. To actually know all of the nodes, but it wouldnt be pathfinding more like pathknowing.
I know this is an old video, but a more effective way of removing a specific element from an array could be written as: var myArr = ["foo", "bar", "bas"] var element = myArr[2] //"bas" function removeFromArray(arr, el) { let i = arr.indexOf(el) if (i > -1) { arr.splice(i, 1) } return arr } myArr = removeFromArray(element)
use filter instead // remove 2 from array [1,2,3].filter(i => i !== 2) I would personally use a linked list if random access is not needed and there is a lot of insertion / deletion happening
In this case your function is definitely better and faster. But it's not equivalent to what he wrote in general. If an array has duplicate elements his function will remove all of them while yours only the first occurrence (assuming that indexOf returns the first occurrence). I just wanted to point that out.
The most effective way is just to use the winner variable, which already had the index of the item (and he instantly forgot that). Just openSet.splice(winner,1)
Does anyone know how to adjust A* in order to find all shortest paths ranked by length in an a-priori manner? Say the current shortest path becomes unpassable due to a storm I need to quickly find the next best alternative path, etc. without having to repeat the entire A* calculation.
first tried to do this without a tutorial. I started at (1, 1)(on a grid) and tried to get to (1, 2). let's just say it went to (-1, 0) then had an infinite loop
25:20 Array's splice method removes one or more elements from an array, closes the gap, and reduces the length. It makes an array of the removed elements, if any, and returns them. You can also insert zero or more new elements in that position by passing them as the subsequent parameters after removal range base and length.
BInary heap implementation of Dijkstra Algorithm runs in O(E)+|V|log|V| time which isn't particularly slow. Together with Hoare's Quicksort Algorithm, Dijkstra Algorithm must rank in the top 2 algorithm of the last century! Excellent job on your videos, you are a great teacher!
You are one of the best teacher online and with a great personality .You have help me a lot with processing. We need more people like you in the world ,thank you.
I have been binge watching your videos over the holiday vacation...and I just don't know how I can express my gratitude for making these amazing videos. Your enthusiasm, presentation style...makes what would be a tough process (learning to program) a VERY enjoyable learning process. A massive thank you for sharing your incredible knowledge. You just got a new member.
@@TheCodingTrain...notbyet! Will do!! Did buy some Coding Train Merch though! What I love the most about the videos you make...is that you don't edit out your mistakes. 'this dot' et all. They are mistakes all of us noobs will make and you show us that even pros make mistakes...and the debugging method is education in itself
I built an A* PF viz in Processing the other day, and I was *this* close to tearing my hair out until I realized how I could simplify away almost half of the code I had written to fix edge cases by just... making a smarter Neighbors() function.
well, ok... but can we create way-finder, but more intelligent? i mean not bruteforcing labirynt, but to look, think, and so right answer without millions of tries?
3:24 - You were wrong about Djkstra algorithm. It doesnt search all the possible paths. Instead it searches only the best path to vertex and uses it to search optimal path to it's neighbors. As it only makes updates from each vertex once and each update only uses one edge(as edge connects 2 vertexes it will only take part in 2 update attempts) it will have complexity O(|E| * upd) . As priority queue is used for updates, upd will have comlexity of O(log(|V|). So total complexity is O(|E| * log(|V|)) which is quiet fast and on average PC it will be able to handle graphs with amounts of edges and vertexes not greater than 100000 in 1 second
I don't want to take anything away from you, it's a great tutorial for understanding A* in a simpler situation. But using a grid with obstacles... does that not sound like a more straightforward Lee algorithm? From what I know, in Dijkstra and A* it's the vertices that have a certain cost, and in a grid that is always 1. Again, it's an awesome idea to simplify the concept, but this time it might be a bit confusing, as you ignore a crucial element from the generalized algorithm, and, even though it's harder to understand for some, I think it just has to use graphs. Amazing channel though. I love your simplicity and enthusiasm.
This is a good video about A* pathfinding, but there are a lot of videos for simple 2d grids. What I miss are tutorials how I can implement A* in a 3d voxel world like Minecraft or Minetest, including jumping, fall height and so on. This is far more complex than the basic 2d grid algorithm
at 25:48 you create a function to find the index of the `current` element, but you already know that value, it is the value stored in `winner`, so I think you could just do `openSet.splice(winner, 1)`, or without side effects: `openSet = openSet.slice(0, winner).concat(openSet.slice(winner + 1, openSet.length))`
trying to translate this into vb however im struggling with drawing the maze and the solution because i cant find a drawing function in vb that would let me do something like this
Sorry, I'm not familiar with this programming language, can someone please explain to me what the issue with 2d arrays is? Why are they not a built in function?
I've been trying to do this on an isometric grid rotated by 22.5 degrees, (2D plane not just a perspective rotation) Talk about heeeeeadache lol, tho I may have just been overcomplicating the sh* out of it
Hello Daniel! Let me start saying that I discovered this channel like a month ago and I totally love it! You have made me start coding again after leaving it for a long time :) I have kind of a silly question for you, I like following your examples and challenges as I'm watching the video, and I try to have the code as organized as you do, but I end up being much slower typing everything and specially spacing everything so it becomes much more readable. How do you make Atom automatically space things out (I'm not refering to indentation inside functions since that came with Atom right out of the box, but rather making a line such as (var i=0, i
26:40 There is no need to traverse the array backward to remove an element from it. Why would it be? (I'll try it in this tutorial's code though.) var arr = [6, 7, 8, 9, 0]; for (var i = arr.length - 1; i >= 0; i--) { if (arr[i] === 7) { arr.splice(i, 1); } } console.log(arr); // [6, 8, 9, 0] for (var j = 0; j < arr.length; j++) { if (arr[j] === 7) { arr.splice(j, 1); } } console.log(arr); // [6, 8, 9, 0]
That's actually not too hard. What you can do is use back tracking. Iterate through each square, and place a 1 in it, check the entire row, make sure nothing else has a 1, check the entire column and make sure no 1, and check the box of 3x3 squares and make sure no 1. If there is a 1, repeat the process with a 2, then a 3 and so forth... If a 9 is tried, and it doesn't work, go to the previous square and increment it by 1, and try that square again. If the code reaches the end, and all the rules are followed, it solved it. If the code back tracked all the way to the beginning and no number works in the first square, the puzzle is unsolvable.
I made one a long time ago but it was not as complicated as the one people propose and it was very efficient time wise. The first step was to have the computer create 81 arrays (Assuming a 9x9 grid). These arrays represents each square. Each of these arrays contain the numbers 1 thru 9. like so square_x1_y1 = [1,2,3,4,5,6,7,8,9], square_x1_y2 = [1,2,3,4,5,6,7,8,9].... square_x9_y9 = [1,2,3,4,5,6,7,8,9] Then you make a 2D array to represent the game board. in each x,y position you put one of the square arrays. 2dArr = [[square_x1_y1, square_x1_y2 ...] ..... ....[square_x9_y8, square_x9_y9]] In short you end up with a 2d array where each element is another array containing the numbers 1 thru 9. The final array is another 2d 9x9 array that contains the numbers the board gives you. From here on you divide the program into 2 parts. the first part is to play the game as a human would do by comparing rows, columns and squares. As long as there is 1 change this part of the program will repeat. What you do is eliminate every number that is already given to you by the game board from each of the arrays that applies to. Let me give you an example. Suppose the first row of the board looks like this. NOTE: E equal an empty square row 1 --> E E 5 E 7 E E E E So start at the first position or (0,0) That position is empty so go to the next (0,1) which is also empty. Now go to the next (0,2) AHA!!!! there is a 5 there. So what you do is eliminate a 5 from every array where a 5 cannot exist. So all of the arrays in row 5 cannot ahve a 5 except for the one in (0,2). All arrays which are in column (0,2) cannot have a 5 either so on and so forth. Do this in sequence and once you reach the end or position (9,9) you stat over because there was a change. Eventually each square array will have fewer and fewer numbers so you will solve 80% of the puzzle. Once the computer can narrow it down any more you use recursion and thats it.
I thought that, (from set theory) that a closed set was a list of all members of the set, (e.g. fruit_I_like = ["apples"]) and an open set is incomplete, all_the_people_that_I_will_ever_meet = { [parents] {siblings} {friends} {acquaintances} ... } (missing "{people that I will meet tomorrow}" and {siblings} set could grow in the future.)
This was super helpful for actually learning A*. I have tried to do it multiple times in C# but never got it working, but ~3 days ago i figured it out thanks to this video. You rock!
I watched this live stream. Must have been the hardest one to edit yet. Probably why part 1 wasn't released until 2 days after haha. Love your channel man, I swear I've put in at least 60 hours watching many of your vids. Btw, I started Frogger today in P5, I think you should consider it for a coding challenge. It's a long and tedious one though!
I’m surprised more code isn’t written for finding a “good enough” path. My guess is that’s what most life does, and when that fails then you look for a better solution, but the amount of effort required to find A path, would be much simpler, yes/no?
Fantastic video! One minor critique, and I don’t mean offense if you too suffer from ADHD but it seems like you are over-stimulated, which brings out lots of quirks in your speaking. I would assume you drank energy drinks/several cups of coffee before recording. This makes it harder to follow along. Thanks for the video!
Jesus Christ is the Way, the Truth, the Life. No one comes to the Father except through Him. There is no other intermediary. May Jesus Bless you, trust Him, give your life - and He will take care of it :pray: Convert yourself and believe in the Gospel
Stopped watching at 11 minutes...i dont mean to offend but your way of explaining does not comply with my way of understanding. I like how Tech With Tim explains his solutions.
star date 2023, a function called filter() to find and remove objects has been invented , and you cover it . i know, because i just finally learned to removed a few items myself, in my useless sort. however , i did succeed at removing array objects
fantastic tutorial! but::: please speak slower, please! since my english is very poor, i have trouble understanding you. so, please continue those wonderful tutorials
dud i watched it to see your implementation of binary heap, what is used to store values and pull minimum value, but you made it pretty trivial. Anyways, thanks :D
I ended up here while trying to fix my own version of A* code for a personal project. Although in a completely different language, I figured following the logic from start to finish would help. I am happy to say that after watching this twice, clocking in at a near 2 hours of of the most energetic coding I've ever observed, I realized one of my i's were a j.
This is an amazing story!!
I feel your pain before notepad++ we had notepad... it was as fun as you described!
I got intense nausea reading that last part.
This is the problem with monospace font glyphs and bad vision. 😂
Classic
I like it how you show the result at the beginning. Otherwise, I always have to go to the end and see if that is something I want to learn.
Yes, I hope to keep doing this with future challenges!
Sometimes it is obvious from description what are you going to do. So, please don't show final result until it really hard to understand!
I personally hate it when he shows the end result at the beginning. At least give a spoiler warning or a timestamp to skip it. For me, seeing the exact end result removes nearly all motivation to watch through an hour long two-part tutorial. I would rather watch the project organically come together as he builds it, without knowing exactly what to expect.
I agree to an extent I like the excitement and motivation of not knowing
You are impatient.
you should make 2048
It is fantastic how this guy has so muck inspiration and energy to program,and a lot of that anergy actually hi is giving to us , BIG THANKS YO HIM :D
Tbh his overly childish display of energy is kind of annoying
@@Nickoking12 you must be fun at parties
Also like his energy and paired with it his intelligence you can hear and see
@@Nickoking12 there are always people that does not want someone be themselves, aren't there...
@@kavinbharathi yep
Name of this channel was different ... I like the new name though !!!
He had trademark issues with Reading Rainbow, so he changed it.
KusKusPL Wasn't it coding rainbow?
Yes, but it was too similar.
Actually ... Even before that ... The channel name was his own name ... "Daniel Shiffman".
Ani H. The channel had always been named Daniel Shiffman, but when he referred to his channel, he called it Coding Rainbow
I love all your Coding Challenge videos. I'd love to see you make a multi-part series of you putting a lot of code and detail into a project.
I know this is a pretty old video, but for anyone watching. The reason it wasnt giving his expected results with no walls and no diagonals is because you need to add tiebreaking in. You can do this simply by changing
for (int i = 0; i < openSet.Count; i++)
{
if (openSet[i].F < openSet[winner].F)
winner = i;
}
Too
for (int i = 0; i < openSet.Count; i++)
{
if (openSet[i].F < openSet[winner].F)
winner = i;
else if (openSet[i].F == openSet[winner].F)//tie breaking
if (openSet[i].H < openSet[winner].H)
winner = i;
}
Thank you for this feedback!
If I had more professors who teach like you I was a better engineer now !
Yeah, the problem is, many of the university teachers are bunch of morons.
if teachers would teach like this you'd need longer days. Of course it's easy to understand when you already know how it's done.
@@MrTrollo2 ikr
31:39 "some other life that you have"
buddy i barely have one life as it is
Best explanation of A* on the internet! By the way, you could have added neighbours to a spot just before looping through its neighbours. This way if you didn't need to check the neighbours of some spots, you wouldn't need to add neighbours to it. They could just be added to closed set without neighbours. This would save a lot of memory when you're dealing with many spots
Your beard is majestic
Man, thank to you again!! I'm so interesting in algorithms and ML, but didn't know where to start. And your lectures are such a good place to start and go far! It's really great, new level, so different to compare with usual front-end JS, it's real science, it's interesting, it's improve you. Thank you!
People like you do more for students than many universities around the world. Cheers to learning 🎉
Wow I'm a whole year late to this video.
Me too :)
yup same
13 months right here
Im 2.5 years late.
Huh novices
1:42 "needle in a haystack"
*Non-premium spotify user's ptsd intensifies*
Not funny
Didn't laugh
Translating this into C# for unity is... interesting. Tough to find a good tutorial on pathfinding, luckily this seems to be working for me so far. Love the videos keep up the great work : )
I had to translate my js code for A* to C for my robotics team a couple of years ago. Great way to learn about pointers and dynamic memory.
Interesting how the animation at the beginning looks a bit like the "stepped leader" of a lightning strike. I wonder if this has any bearing on that phenomenon, which I believe isn't that well understood - could be an opportunity for some cross-disciplinary research.... :)
Actually, a lightning IS looking for the shorter way ! So i thinks that it's pretty much the same thing :)
Sorry for my english i'm french ^^
Exactly the comment i was looking for!
Algorithm for resolve a sudoku
I did this a few years ago in one of my intro classes to programming. Was hell, still have the file though :)
This guy is a genius! It looks so straight forward every single step. Amazing 🤩
26:35 if splice removes an element in the given index of the array, couldn't you use it as instead of creating the function removeFromArray? Loving the content ❤
yes.. Let's just say his brain's think quicker than a machine already so he doesn't need that extra optimisation :')
You should do coding challenges on different languages, such as python or CPP
Oh right. Python is much harder than JS XD
@@scholli99 that was not the point even if python is easier writing the code is as challenging as js
Well p5 is a js library, and p3 is a java library, so it wouldn't make much sense to switch up those languages.
@@scholli99 That's not the point...
What he meant was, to do different languages for educational purposes it's not just about the difficulty, after all this channel is for sharing information about programming.
Thumbs up if you can taste the rainbow.
Hello, thank you for your video. I have implemented the A Star on Android Studio.
Can I share it with you ?
Have you ever though of making a Robot Localization with particles filter on simulation ? I have implemented it this weekend.
When I will go to USA, I will meet you no matter what. I love you, man ❤️
Mimics nature. Question is, is this the absolute pinnacle of pathfinding. What other 'better' ways could there be. To actually know all of the nodes, but it wouldnt be pathfinding more like pathknowing.
I honestly don't know what I would do without you.
I know this is an old video, but a more effective way of removing a specific element from an array could be written as:
var myArr = ["foo", "bar", "bas"]
var element = myArr[2] //"bas"
function removeFromArray(arr, el) {
let i = arr.indexOf(el)
if (i > -1) {
arr.splice(i, 1)
}
return arr
}
myArr = removeFromArray(element)
use filter instead
// remove 2 from array
[1,2,3].filter(i => i !== 2)
I would personally use a linked list if random access is not needed and there is a lot of insertion / deletion happening
In this case your function is definitely better and faster. But it's not equivalent to what he wrote in general. If an array has duplicate elements his function will remove all of them while yours only the first occurrence (assuming that indexOf returns the first occurrence). I just wanted to point that out.
@@xerxius5446 I agree. I was referring to the code in the parent comment, not yours :)
The most effective way is just to use the winner variable, which already had the index of the item (and he instantly forgot that). Just openSet.splice(winner,1)
Looks just like a robot finding an optimal path through a building. ;)
For any of you wondering, this is the kind of algorithm top down view rpgs and mobas use like league, runescape, fallout etc
i like Coding Trainbow more xD
Agreed!
The Coding Train I'd laugh if you actually changed your name to that temporarily
@@TheCodingTrain The new name is way better.
25:18: Since we know that the index of current is winner, could we not just use openSet.splice(winner,1) ?
yes
Does anyone know how to adjust A* in order to find all shortest paths ranked by length in an a-priori manner? Say the current shortest path becomes unpassable due to a storm I need to quickly find the next best alternative path, etc. without having to repeat the entire A* calculation.
first tried to do this without a tutorial. I started at (1, 1)(on a grid) and tried to get to (1, 2). let's just say it went to (-1, 0) then had an infinite loop
It is fantastic how this guy has so muck inspiration and energy to program,and a lot of that anergy actually hi is giving to us , BIG THANKS YO HIM :D
Awesome dear genius.
Jesus loves you. Believe in him and repent.
18:18 "Are you still watching?"
0 views
To remove a value from an array in javascript, the two main solutions I know are .filter and .splice(.indexOf)
25:20 Array's splice method removes one or more elements from an array, closes the gap, and reduces the length. It makes an array of the removed elements, if any, and returns them. You can also insert zero or more new elements in that position by passing them as the subsequent parameters after removal range base and length.
* spoiler alert * there will be 3 parts!
BInary heap implementation of Dijkstra Algorithm runs in O(E)+|V|log|V| time which isn't particularly slow. Together with Hoare's Quicksort Algorithm, Dijkstra Algorithm must rank in the top 2 algorithm of the last century!
Excellent job on your videos, you are a great teacher!
Interesting coding chanel but the videos are old, it's cool if a new videos will be posted
Could you try to make a neural network that learns and can play games like Mario or some other game that would work well
did you find one ?
You are one of the best teacher online and with a great personality .You have help me a lot with processing. We need more people like you in the world ,thank you.
Thanks for the nice comment!
i don't understand any of that but i find it fascinating!
in the for loop with at 12:25 lines 14-16.
shouldn't the rows be first and then the columns?
I mean when you iterate through the 2D array you choose the row first and then the columns.
arr = [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]
arr[0][0] is 1st row 1st column not 1st column 1st row.
am I missing something here?
yes, he used cols for rows and visa versa
Really Really Really!!!! Fantastic Video. I really love his energy while he was teaching!! Wish I could have this man as my professor. Amazing!!
I have been binge watching your videos over the holiday vacation...and I just don't know how I can express my gratitude for making these amazing videos. Your enthusiasm, presentation style...makes what would be a tough process (learning to program) a VERY enjoyable learning process. A massive thank you for sharing your incredible knowledge. You just got a new member.
Thank you Rico! Did you fill out the google form and link your account to Discord?
@@TheCodingTrain...notbyet! Will do!! Did buy some Coding Train Merch though!
What I love the most about the videos you make...is that you don't edit out your mistakes. 'this dot' et all. They are mistakes all of us noobs will make and you show us that even pros make mistakes...and the debugging method is education in itself
@@sennabullet Thanks, I really appreciate this feedback!
Go to the coding Choppa !
Gregzenegair Skynet
"put the cookie down" - Arnold Schwarzenegger
I built an A* PF viz in Processing the other day, and I was *this* close to tearing my hair out until I realized how I could simplify away almost half of the code I had written to fix edge cases by just... making a smarter Neighbors() function.
well, ok... but can we create way-finder, but more intelligent? i mean not bruteforcing labirynt, but to look, think, and so right answer without millions of tries?
3:24 - You were wrong about Djkstra algorithm. It doesnt search all the possible paths. Instead it searches only the best path to vertex and uses it to search optimal path to it's neighbors. As it only makes updates from each vertex once and each update only uses one edge(as edge connects 2 vertexes it will only take part in 2 update attempts) it will have complexity O(|E| * upd) . As priority queue is used for updates, upd will have comlexity of O(log(|V|). So total complexity is O(|E| * log(|V|)) which is quiet fast and on average PC it will be able to handle graphs with amounts of edges and vertexes not greater than 100000 in 1 second
Omg he move so much that I got tired after a few minutes of watching
I don't want to take anything away from you, it's a great tutorial for understanding A* in a simpler situation. But using a grid with obstacles... does that not sound like a more straightforward Lee algorithm? From what I know, in Dijkstra and A* it's the vertices that have a certain cost, and in a grid that is always 1. Again, it's an awesome idea to simplify the concept, but this time it might be a bit confusing, as you ignore a crucial element from the generalized algorithm, and, even though it's harder to understand for some, I think it just has to use graphs. Amazing channel though. I love your simplicity and enthusiasm.
Best tutorial seen so far on A* algorithm
This is a good video about A* pathfinding, but there are a lot of videos for simple 2d grids. What I miss are tutorials how I can implement A* in a 3d voxel world like Minecraft or Minetest, including jumping, fall height and so on. This is far more complex than the basic 2d grid algorithm
Very well explained, thanks! Love your enthusiasm for teaching!
I loved the part when pathfinder says "get ready, its Zipline time" and start pathfinding all over the place
at 25:48 you create a function to find the index of the `current` element, but you already know that value, it is the value stored in `winner`, so I think you could just do `openSet.splice(winner, 1)`, or without side effects: `openSet = openSet.slice(0, winner).concat(openSet.slice(winner + 1, openSet.length))`
Thanks !!! You helped me a lot, and that works for Hex grids! (Of course just have to change neighbors conditions)
Finally sunder pitchai's official youtube channel😂🤘
25:40 why dont you just use "openSet.splice(winner,1);" ?
Right!
yesss A*!! awesome
dude, I f*ing LOVE your website!
26:37
removeFromArr = (a, e) => {
var i = a.lastIndexOf(e);
a.splice(i, 1);
}
This channel always when i don’t know what to do when i want to code something gives me motivation and ideas, pretty cool.
trying to translate this into vb however im struggling with drawing the maze and the solution because i cant find a drawing function in vb that would let me do something like this
Sorry, I'm not familiar with this programming language, can someone please explain to me what the issue with 2d arrays is? Why are they not a built in function?
Danicker A 2D array is just an array of arrays. What is built in a language is just a design choice.
it is a built in method for arrays, if you use:
array.forEach(function(arrayItem, numIndex){ //do something with arrayItem });
I've been trying to do this on an isometric grid rotated by 22.5 degrees, (2D plane not just a perspective rotation)
Talk about heeeeeadache lol, tho I may have just been overcomplicating the sh* out of it
Absolutely amazing video! Your energy for coding is absolutely amazing and got me coding in p5
Hello Daniel! Let me start saying that I discovered this channel like a month ago and I totally love it! You have made me start coding again after leaving it for a long time :)
I have kind of a silly question for you, I like following your examples and challenges as I'm watching the video, and I try to have the code as organized as you do, but I end up being much slower typing everything and specially spacing everything so it becomes much more readable. How do you make Atom automatically space things out (I'm not refering to indentation inside functions since that came with Atom right out of the box, but rather making a line such as (var i=0, i
26:40 There is no need to traverse the array backward to remove an element from it. Why would it be? (I'll try it in this tutorial's code though.)
var arr = [6, 7, 8, 9, 0];
for (var i = arr.length - 1; i >= 0; i--) {
if (arr[i] === 7) {
arr.splice(i, 1);
}
}
console.log(arr);
// [6, 8, 9, 0]
for (var j = 0; j < arr.length; j++) {
if (arr[j] === 7) {
arr.splice(j, 1);
}
}
console.log(arr);
// [6, 8, 9, 0]
create a soduko solving algorithm!
That's actually not too hard.
What you can do is use back tracking.
Iterate through each square, and place a 1 in it, check the entire row, make sure nothing else has a 1, check the entire column and make sure no 1, and check the box of 3x3 squares and make sure no 1. If there is a 1, repeat the process with a 2, then a 3 and so forth...
If a 9 is tried, and it doesn't work, go to the previous square and increment it by 1, and try that square again.
If the code reaches the end, and all the rules are followed, it solved it. If the code back tracked all the way to the beginning and no number works in the first square, the puzzle is unsolvable.
i could do that, but it is so non efficient it is crazy. solving a soduko would take a lot of time.
en.wikipedia.org/wiki/Sudoku_solving_algorithms
I made one a long time ago but it was not as complicated as the one people propose and it was very efficient time wise. The first step was to have the computer create 81 arrays (Assuming a 9x9 grid). These arrays represents each square. Each of these arrays contain the numbers 1 thru 9. like so
square_x1_y1 = [1,2,3,4,5,6,7,8,9], square_x1_y2 = [1,2,3,4,5,6,7,8,9].... square_x9_y9 = [1,2,3,4,5,6,7,8,9]
Then you make a 2D array to represent the game board. in each x,y position you put one of the square arrays.
2dArr = [[square_x1_y1, square_x1_y2 ...]
.....
....[square_x9_y8, square_x9_y9]]
In short you end up with a 2d array where each element is another array containing the numbers 1 thru 9.
The final array is another 2d 9x9 array that contains the numbers the board gives you.
From here on you divide the program into 2 parts. the first part is to play the game as a human would do by comparing rows, columns and squares. As long as there is 1 change this part of the program will repeat. What you do is eliminate every number that is already given to you by the game board from each of the arrays that applies to. Let me give you an example.
Suppose the first row of the board looks like this. NOTE: E equal an empty square
row 1 --> E E 5 E 7 E E E E
So start at the first position or (0,0) That position is empty so go to the next (0,1) which is also empty. Now go to the next (0,2) AHA!!!! there is a 5 there. So what you do is eliminate a 5 from every array where a 5 cannot exist. So all of the arrays in row 5 cannot ahve a 5 except for the one in (0,2). All arrays which are in column (0,2) cannot have a 5 either so on and so forth. Do this in sequence and once you reach the end or position (9,9) you stat over because there was a change. Eventually each square array will have fewer and fewer numbers so you will solve 80% of the puzzle. Once the computer can narrow it down any more you use recursion and thats it.
In 25:46 can you say openSet.splice(winner,1); at line 72?
yes
Coding Helicopter...?
CODING PLANE ALL ABOARD THE CODING PLANE
I thought that, (from set theory) that a closed set was a list of all members of the set, (e.g. fruit_I_like = ["apples"]) and an open set is incomplete, all_the_people_that_I_will_ever_meet = { [parents] {siblings} {friends} {acquaintances} ... } (missing "{people that I will meet tomorrow}" and {siblings} set could grow in the future.)
This was super helpful for actually learning A*. I have tried to do it multiple times in C# but never got it working, but ~3 days ago i figured it out thanks to this video. You rock!
coding copter has a ring to it
I watched this live stream. Must have been the hardest one to edit yet. Probably why part 1 wasn't released until 2 days after haha. Love your channel man, I swear I've put in at least 60 hours watching many of your vids. Btw, I started Frogger today in P5, I think you should consider it for a coding challenge. It's a long and tedious one though!
Frogger is a great idea.
20:46 that's racist
I’m surprised more code isn’t written for finding a “good enough” path. My guess is that’s what most life does, and when that fails then you look for a better solution, but the amount of effort required to find A path, would be much simpler, yes/no?
So after a mess and 2 hours you finished it? You are BRILLIANT my friend!
Chapter 10 of the "Nature of Code" Book would be nice :D
Fantastic video! One minor critique, and I don’t mean offense if you too suffer from ADHD but it seems like you are over-stimulated, which brings out lots of quirks in your speaking. I would assume you drank energy drinks/several cups of coffee before recording. This makes it harder to follow along. Thanks for the video!
Jesus Christ is the Way, the Truth, the Life. No one comes to the Father except through Him. There is no other intermediary. May Jesus Bless you, trust Him, give your life - and He will take care of it :pray: Convert yourself and believe in the Gospel
3:35 Dijkstra's Algorithm, although does find you the optimal path, but it absolutely doesn't try all the paths, it's a Greedy Algorithm
First :D
found out about this channel afew days ago. your videos and walkthroughs are amazing.
Stopped watching at 11 minutes...i dont mean to offend but your way of explaining does not comply with my way of understanding. I like how Tech With Tim explains his solutions.
star date 2023, a function called filter() to find and remove objects has been invented , and you cover it . i know, because i just finally learned to removed a few items myself, in my useless sort. however , i did succeed at removing array objects
fantastic tutorial! but::: please speak slower, please! since my english is very poor, i have trouble understanding you. so, please continue those wonderful tutorials
Lmao i started the video and thought, huh he's talking pretty fast in this video. Weird. Took me 2 minutes to realize it was on x1.5 speed lol
Wow ,you just programmed a Printed Circuit Board Auto Router!!!😲😲
136 dislike => javascrpit bilmeyenler(not know javascript people)
damn, i already know some of java, i want to learn javascript but i REALLY hate maths
Please make video on a 9/15 puzzle solving algorithm ... I read somewhere that it uses a* algorithm ...
I'll look into it!
I don't get why at 21:46 you still have a visible grid, although you used noStroke()?
Hello genius, I need a favor, could you explain the LPA* algorithm
ES 6 please!!!!
dud i watched it to see your implementation of binary heap, what is used to store values and pull minimum value, but you made it pretty trivial. Anyways, thanks :D