1
00:00:00,210 --> 00:00:03,480
-: Let's actually recall from a previous lesson,

2
00:00:03,480 --> 00:00:05,370
this LeetCode problem, right?

3
00:00:05,370 --> 00:00:09,783
So what if we tinker with some of these things here, right?

4
00:00:10,817 --> 00:00:15,060
And just, just to, just to prove the point, let's actually,

5
00:00:15,060 --> 00:00:18,240
this, this is a different chat window from the other chat

6
00:00:18,240 --> 00:00:21,690
that we had where we gave them the LeetCode link.

7
00:00:21,690 --> 00:00:26,690
So let's say I have the following sequence

8
00:00:27,090 --> 00:00:31,923
or the following problem statement and paste that in.

9
00:00:32,887 --> 00:00:37,887
"My solution is not working. Why?"

10
00:00:38,490 --> 00:00:41,370
And then let's go ahead and paste in a modified version

11
00:00:41,370 --> 00:00:45,690
where we kind of screw up the binary search, add a one here,

12
00:00:45,690 --> 00:00:49,200
let's put a two here,

13
00:00:49,200 --> 00:00:52,020
and let's maybe even misspell, misspell "right" here

14
00:00:52,020 --> 00:00:54,390
to become light, right?

15
00:00:54,390 --> 00:00:57,090
And let's see if it's able to pick out some of these issues.

16
00:00:57,090 --> 00:01:00,930
So clearly, first of all, there's a big issue in the logic,

17
00:01:00,930 --> 00:01:03,150
like it shouldn't even be correct.

18
00:01:03,150 --> 00:01:04,980
And secondly, there's a syntax error,

19
00:01:04,980 --> 00:01:07,110
which doesn't even allow it to compile correctly

20
00:01:07,110 --> 00:01:09,000
because light has never been declared

21
00:01:09,000 --> 00:01:11,250
as a variable in this, in this function.

22
00:01:11,250 --> 00:01:13,560
So the, the issue in your solution is with the calculation

23
00:01:13,560 --> 00:01:15,030
of the middle index mid.

24
00:01:15,030 --> 00:01:20,030
So that is, that's perfectly fine. So let's see here.

25
00:01:20,280 --> 00:01:23,250
The things we ended up changing is this mod function here,

26
00:01:23,250 --> 00:01:26,310
and let's see what they give us.

27
00:01:26,310 --> 00:01:28,860
Yep, they've changed our mod right back to two.

28
00:01:28,860 --> 00:01:31,680
You should be divided by two to get to the middle index.

29
00:01:31,680 --> 00:01:33,870
Change the calculation of mid

30
00:01:33,870 --> 00:01:35,460
and allow your solution to work instead.

31
00:01:35,460 --> 00:01:37,290
Yeah. So he's also made,

32
00:01:37,290 --> 00:01:39,960
or sorry, ChatGPT has made a few other modifications

33
00:01:39,960 --> 00:01:42,060
to the code, including the check

34
00:01:42,060 --> 00:01:45,960
for mid mod three equals zero to mid mod two equals zero

35
00:01:45,960 --> 00:01:47,790
as well as a typo.

36
00:01:47,790 --> 00:01:49,680
So it's talking about literally everything

37
00:01:49,680 --> 00:01:51,660
that it's fixed for us.

38
00:01:51,660 --> 00:01:54,210
And if we go ahead and paste that in, I'm, I don't doubt

39
00:01:54,210 --> 00:01:58,230
that this is pretty much what we had had before, but yeah,

40
00:01:58,230 --> 00:02:01,440
nonetheless, it's a correct solution now.

41
00:02:01,440 --> 00:02:03,510
And yeah, that works perfect.

42
00:02:03,510 --> 00:02:05,010
It knew, it knew exactly what we had fixed,

43
00:02:05,010 --> 00:02:07,590
even though this is a different context from the

44
00:02:07,590 --> 00:02:09,870
conversation that we had in the previous lesson.

45
00:02:09,870 --> 00:02:10,860
So it actually remembers those

46
00:02:10,860 --> 00:02:12,210
things, which is really interesting.

47
00:02:12,210 --> 00:02:16,560
Maybe we could even go back even further to a previous time

48
00:02:16,560 --> 00:02:19,110
where we talked about primes, right?

49
00:02:19,110 --> 00:02:22,630
So what if, what if we say

50
00:02:24,600 --> 00:02:28,410
So remember the Sieve of Eratosthenes needs,

51
00:02:28,410 --> 00:02:29,940
needs to have a certain range of numbers

52
00:02:29,940 --> 00:02:31,140
that it goes through, right?

53
00:02:31,140 --> 00:02:32,970
So let's start it at five

54
00:02:32,970 --> 00:02:36,150
and then let's have it go up until, not the square root

55
00:02:36,150 --> 00:02:40,920
of X, but two, like a squared of X, right?

56
00:02:40,920 --> 00:02:45,920
So let's see, "Why is my algorithm to generate primes

57
00:02:49,170 --> 00:02:52,554
slow and incorrect?" Because now not only

58
00:02:52,554 --> 00:02:54,900
are we not going up into

59
00:02:54,900 --> 00:02:57,510
a square root factor of our input number X,

60
00:02:57,510 --> 00:02:59,760
but now we're going to a power of it.

61
00:02:59,760 --> 00:03:03,510
And then we're also messing with the starting number.

62
00:03:03,510 --> 00:03:08,290
So this is literally not even gonna find the factors 2, 3, 4

63
00:03:08,290 --> 00:03:11,880
for numbers, which is gonna be extremely problematic, right?

64
00:03:11,880 --> 00:03:14,070
So let's see if it's able to pick out what's wrong with

65
00:03:14,070 --> 00:03:15,900
that after I change it.

66
00:03:15,900 --> 00:03:17,190
It's incorrect because it's a range

67
00:03:17,190 --> 00:03:19,890
and the outer loop should be two to the square root of X,

68
00:03:19,890 --> 00:03:21,720
not five to the square of x.

69
00:03:21,720 --> 00:03:24,540
Dang, this is really good at,

70
00:03:24,540 --> 00:03:26,910
this is this ChatGPT thing is really something else.

71
00:03:26,910 --> 00:03:28,320
It's, yeah, so I mean,

72
00:03:28,320 --> 00:03:30,150
if you're implementing some well known algorithm

73
00:03:30,150 --> 00:03:31,470
and you just don't know what's wrong

74
00:03:31,470 --> 00:03:33,420
and you're getting some like incorrect input,

75
00:03:33,420 --> 00:03:34,530
this thing is insane.

76
00:03:34,530 --> 00:03:36,990
Like it can really just pick out the flaws

77
00:03:36,990 --> 00:03:40,320
with your algorithm and give you the corrections

78
00:03:40,320 --> 00:03:42,060
that you need to make quite simply.

79
00:03:42,060 --> 00:03:44,400
So yeah, and it even explains why, right?

80
00:03:44,400 --> 00:03:46,920
It says the reason why this algorithm is efficient is

81
00:03:46,920 --> 00:03:49,200
because you only need a check up to the square root of x,

82
00:03:49,200 --> 00:03:52,110
which this, this is a very big component

83
00:03:52,110 --> 00:03:55,080
of the really fast run time that this algorithm has.

84
00:03:55,080 --> 00:03:58,260
So if we iterate more right up until the square of X,

85
00:03:58,260 --> 00:04:00,540
that's just wasting a lot of compute

86
00:04:00,540 --> 00:04:02,580
and giving us an incorrect answer.

87
00:04:02,580 --> 00:04:05,790
So yeah, it's telling us exactly what's wrong.

88
00:04:05,790 --> 00:04:07,110
So this is really powerful

89
00:04:07,110 --> 00:04:09,660
and if you know what you're doing, like once you've gone

90
00:04:09,660 --> 00:04:13,590
to this point as a coder where you're able

91
00:04:13,590 --> 00:04:16,869
to write your own code, ChatGPT can be a really useful tool

92
00:04:16,869 --> 00:04:20,070
for kind of understanding what you may be doing wrong

93
00:04:20,070 --> 00:04:22,320
as long as you're able to provide the

94
00:04:22,320 --> 00:04:23,700
problem statement, right?

95
00:04:23,700 --> 00:04:27,660
So the first and foremost important thing is to tell them

96
00:04:27,660 --> 00:04:29,700
what your goal is, right?

97
00:04:29,700 --> 00:04:31,680
So in the same way that for code generation,

98
00:04:31,680 --> 00:04:33,090
you have an idea of what, what kind

99
00:04:33,090 --> 00:04:35,040
of code you want generated in the first place.

100
00:04:35,040 --> 00:04:38,550
Here with debugging, you need to tell ChatGPT what it is

101
00:04:38,550 --> 00:04:41,280
that you want your program to accomplish in the first place

102
00:04:41,280 --> 00:04:43,050
so that it can help you generate

103
00:04:43,050 --> 00:04:44,160
the correct behavior, right?

104
00:04:44,160 --> 00:04:47,550
So here I told it I was trying to generate primes, so that's

105
00:04:47,550 --> 00:04:49,230
how it knew what it needed to fix.

106
00:04:49,230 --> 00:04:51,810
Hopefully this is helpful for you to understand

107
00:04:51,810 --> 00:04:54,300
how ChatGPT can help you debug.

108
00:04:54,300 --> 00:04:56,040
And I'll see you in the next video

109
00:04:56,040 --> 00:04:57,663
talking about documentation.

