-: Let's actually recall from a previous lesson,
this LeetCode problem, right?
So what if we tinker with some of these things here, right?
And just, just to, just to prove the point, let's actually,
this, this is a different chat window from the other chat
that we had where we gave them the LeetCode link.
So let's say I have the following sequence
or the following problem statement and paste that in.
"My solution is not working. Why?"
And then let's go ahead and paste in a modified version
where we kind of screw up the binary search, add a one here,
let's put a two here,
and let's maybe even misspell, misspell "right" here
to become light, right?
And let's see if it's able to pick out some of these issues.
So clearly, first of all, there's a big issue in the logic,
like it shouldn't even be correct.
And secondly, there's a syntax error,
which doesn't even allow it to compile correctly
because light has never been declared
as a variable in this, in this function.
So the, the issue in your solution is with the calculation
of the middle index mid.
So that is, that's perfectly fine. So let's see here.
The things we ended up changing is this mod function here,
and let's see what they give us.
Yep, they've changed our mod right back to two.
You should be divided by two to get to the middle index.
Change the calculation of mid
and allow your solution to work instead.
Yeah. So he's also made,
or sorry, ChatGPT has made a few other modifications
to the code, including the check
for mid mod three equals zero to mid mod two equals zero
as well as a typo.
So it's talking about literally everything
that it's fixed for us.
And if we go ahead and paste that in, I'm, I don't doubt
that this is pretty much what we had had before, but yeah,
nonetheless, it's a correct solution now.
And yeah, that works perfect.
It knew, it knew exactly what we had fixed,
even though this is a different context from the
conversation that we had in the previous lesson.
So it actually remembers those
things, which is really interesting.
Maybe we could even go back even further to a previous time
where we talked about primes, right?
So what if, what if we say
So remember the Sieve of Eratosthenes needs,
needs to have a certain range of numbers
that it goes through, right?
So let's start it at five
and then let's have it go up until, not the square root
of X, but two, like a squared of X, right?
So let's see, "Why is my algorithm to generate primes
slow and incorrect?" Because now not only
are we not going up into
a square root factor of our input number X,
but now we're going to a power of it.
And then we're also messing with the starting number.
So this is literally not even gonna find the factors 2, 3, 4
for numbers, which is gonna be extremely problematic, right?
So let's see if it's able to pick out what's wrong with
that after I change it.
It's incorrect because it's a range
and the outer loop should be two to the square root of X,
not five to the square of x.
Dang, this is really good at,
this is this ChatGPT thing is really something else.
It's, yeah, so I mean,
if you're implementing some well known algorithm
and you just don't know what's wrong
and you're getting some like incorrect input,
this thing is insane.
Like it can really just pick out the flaws
with your algorithm and give you the corrections
that you need to make quite simply.
So yeah, and it even explains why, right?
It says the reason why this algorithm is efficient is
because you only need a check up to the square root of x,
which this, this is a very big component
of the really fast run time that this algorithm has.
So if we iterate more right up until the square of X,
that's just wasting a lot of compute
and giving us an incorrect answer.
So yeah, it's telling us exactly what's wrong.
So this is really powerful
and if you know what you're doing, like once you've gone
to this point as a coder where you're able
to write your own code, ChatGPT can be a really useful tool
for kind of understanding what you may be doing wrong
as long as you're able to provide the
problem statement, right?
So the first and foremost important thing is to tell them
what your goal is, right?
So in the same way that for code generation,
you have an idea of what, what kind
of code you want generated in the first place.
Here with debugging, you need to tell ChatGPT what it is
that you want your program to accomplish in the first place
so that it can help you generate
the correct behavior, right?
So here I told it I was trying to generate primes, so that's
how it knew what it needed to fix.
Hopefully this is helpful for you to understand
how ChatGPT can help you debug.
And I'll see you in the next video
talking about documentation.