we've been using exhaustive algorithms 我们一直在使用穷举算法
guess and Chuck algorithms to solve some 猜测和查克算法来解决一些问题
simple numerical problems but if you 简单的数值问题，但是如果你
think about it they've all been doing 想一想他们都在做
things with integers where there is a 有整数的东西
finite number of choices that we have to 我们必须选择的数量有限
check and that makes sense 检查，这很有意义
I can certainly run through all of them 我当然可以经历所有这些
until I get to either the right answer 直到我找到正确的答案
or determine there isn't a possible 或确定没有可能
answer but now suppose we want to find 回答，但现在假设我们想找到
say the square root of the cube root of 说方根的平方根
any non-negative number it could be an 任何非负数都可以是
integer could be a float it could be any 整数可以是浮点数，也可以是任何整数
number 数
I can't generate all possible guesses 我无法产生所有可能的猜测
they're infinite so I can't in this case 他们是无限的，所以我不能在这种情况下
guaranteed an exact answer but I could 保证确切的答案，但我可以
come close now what I just want to do is 现在关闭我只想做的是
try and find a guess that's close enough 尝试找到足够接近的猜测
to the cube root of the square root of 到的平方根的立方根
the thing I'm looking for I can still 我正在寻找的东西我仍然可以
use that notion of exhaustive 使用详尽的概念
enumeration but I'm going to now have to 枚举，但我现在必须
pick examples where I take small steps 选择一些我采取小步骤的例子
in order to generate the guess and check 为了产生猜测和检查
to see if I'm close enough let's see 看看我是否足够近，让我们来看看
what that might look like here the idea 这个想法可能看起来像什么
is I have to define what's a good enough 我必须定义什么才是足够的
solution so I'm going to start with a 解决方案，所以我将从一个
guess say 1 I'm going to check to see if 猜想说1我要检查是否
that's close enough if it is only going 如果只去的话，那已经足够接近了
to change it by a tiny amount say one 稍微改变一下
point zero zero one check that one it's 点零零一检查那是一
and then one point zero zero two and 然后一分零零二和
keep doing that so I don't need to 继续这样做，所以我不需要
increment by some small value as I go 在我走的时候增加一些小值
along but I also have to define what 但是我也必须定义
does it mean to get close enough it 这是否意味着足够接近它
won't be exactly the same because I'm 不会完全一样，因为我
not going to be able to guarantee that 不能保证
so here I'm going to use in the case of 所以在这里我将使用
cube root something that tells me 立方根的东西告诉我
whether I'm close enough by looking at 看我是否足够亲近
cute that's right the guess cubed take 很可爱，猜对了
the absolute value in case it's negative 如果是负数，则为绝对值
and look at the difference between that 看一下两者之间的区别
and cube to see if it's less than or 和立方体，看它是否小于或
equal to a small number and if it is I'm 等于一个小数，如果是的话
gonna say I'm close enough and I'm going 要说我足够亲密，我要去
to stop one of the tricks here is that 阻止这里的窍门之一是
when I have these small values I'm gonna 当我拥有这些小的价值时，我会
have to be careful if I make them really 如果我真的把它们做成，一定要小心
small I'll make sure I find a really 小我会确保我找到一个真正的
good guess but it's gonna slow the 很好的猜测，但这会减慢
program down if I make them really large 如果我把它们做得很大，就调低程序
I might actually miss the answer and 我可能实际上错过了答案，
similarly when I decide how close I want 同样，当我决定要关闭多远时
to get with epsilon if I make epsilon 如果我做epsilon可以和epsilon一起使用
big when I make it easier to find an 当我更容易找到一个
answer but I might get a less accurate 回答，但我可能不太准确
answer and so I have to think carefully 回答，所以我必须仔细考虑
about how I 关于我
do both of those but let's look at that 两者都做，但让我们来看一下
idea to see how I can still use the idea 看看我如何仍然可以使用这个想法
of guess and check but now with things 猜测和检查，但现在有了东西
that could compute the cube root of 可以计算出的立方根
anything so here's an example I'm gonna 任何事情，这是我要举的一个例子
start off with some value that for the 从一些价值开始
thing I'm trying to find the cube of 27 我试图找到27的多维数据集
is gonna be an easy one I'm going to set 我将要设置的一个简单的
up some initial values epsilon is going 一些初始值epsilon要去
to be something that tells me how close 告诉我有多近
I want to get to the answer 我想得到答案
guess is where I'm going to start and 猜猜是我要开始的地方，
increments the size in which I'm going 增加我要走的尺寸
to increase my guess as I move along and 当我前进时增加我的猜测
just to keep track of it I'm going to 只是为了跟踪它，我要
set up another variable called number of 设置另一个称为number of的变量
guesses 猜测
I'm going to use that to keep track of 我将使用它来跟踪
how many times do I go through the loop 我要循环几次
as I do this and then what does this 当我这样做，然后这是什么
code do it says wow the difference 代码做到了，哇，与众不同
between the cube or your guest cubed and 在立方体或客人立方体之间
the thing I'm trying to find the cube 我试图找到立方体的东西
root of while that difference is still 差异的根源仍然存在
bigger than Epsilon 比Epsilon大
I'm going to keep going by incrementing 我将继续增加
guess by increment there's that plus 通过增量猜测有
equal that I've used before and changing 等于我以前使用和更改
number of guesses by one saying I've 一句话我猜的数目
done another guess and keep going I'm 做了另一个猜测，继续前进，我是
going to keep doing that until I get to 继续做下去直到我明白
something where the difference between 两者之间的区别
guest cubed and cube is small enough and 来宾立方和立方足够小，
at that point I'm going to stop and I 那时候我要停下来，我
want to return both how many guesses did 想同时返回多少个猜测
I run and some information of what did I 我跑了，我做了些什么的信息
find the right answer let's see what 找到正确的答案，让我们看看
happens if I run that so there's a piece 如果我运行那样会发生，所以有一块
of code let me start with 27 just the 代码让我从27开始
thing I had before and if I load that 我以前的东西，如果我加载
and run it ha it gives me oh not quite 并运行它哈给我哦，不太
the answer I expected it says two point 我预期的答案说两点
nine nine seven zero zero zero zero zero 九九七零零零零零
zero one 906 is close to the cube root 零906靠近立方根
of 27 and that's true we're gonna see us 27岁，这是真的，我们要去看看我们
in a little bit why it doesn't just give 有点为什么它不只是给
me three it gives me this funny answer 我三个，这给了我这个有趣的答案
in there but you can also see that it 在那里，但您也可以看到它
took almost 30,000 times through the 通过了将近30,000次
loop before it got to that why because I 循环之前，为什么，因为我
started with a very simple answer zero 从一个非常简单的答案零开始
that wasn't close enough then I went to 距离不够近，我去了
0.0001 then zero point zero zero zero 0.0001然后零点零零零
two and you can see I'm gonna have to do 两个，你会看到我要做
a lot of things until I get to something 很多事情，直到我有所了解
that's going to give me a good 那会给我一个很好的
now I could pick another example let's 现在我可以再举一个例子
make it 29 which I know is not a cube 使其变成29我知道不是立方体
root let's see what happens if I do that 根，让我们看看如果我那样做会发生什么
it's not a perfect cube but in this case 它不是一个完美的立方体，但在这种情况下
it found it that's actually nice 它发现它实际上很好
in the previous case I could only find 在以前的情况下，我只能找到
things that were cube roots of integers 整数的立方根的东西
now I've got something where the cube 现在我有东西在立方体
root isn't an integer but I can still 根不是整数，但我仍然可以
find it this took almost 31,000 times 发现这花了将近31,000次
through the loop so I could say you know 通过循环，所以我可以说你知道
what I want to use something where I'm 我想在我所在的地方使用的东西
gonna step a little more broadly let's 让我们更广泛地迈出一步
step every thousandth of a step rather 每千分之一步
than every ten thousands of a step and 比每一万步
now if I run it okay I get a little bit 现在，如果我运行它，好了，我会得到一点
different guess but it only took three 不同的猜测，但只花了三个
thousand trials through it and if I 一千次尝试，如果我
change it to say this the increment 更改为增量
should be in hundreds I can run that and 应该成百上千我可以运行
if I do that I'm sorry it decided it 如果我这样做我很抱歉它决定了
didn't like that let me think about why 不喜欢我让我想一想为什么
it didn't like that ah what's happened 那不喜欢啊发生了什么事
here it's often an infinite loop and the 这里通常是一个无限循环，
reason it's often an infinite loop is 通常是无限循环的原因是
because I'm checking only to see if I 因为我只检查我是否
get to a place where it's close enough 到足够近的地方
I've actually gone right past the cube 我实际上已经越过立方体
root and it's still running so I need to 根，它仍然在运行，所以我需要
stop this and I'm going to interrupt it 停止这个，我要打断它
to hold it back that's something I need 阻止它，这是我需要的
to fix so if I go back to a little bit 修复，所以如果我再回到一点
better increment here and rerun it I get 最好在这里增加并重新运行它
back to the thing I wanted to have okay 回到我想要的东西上
how would I fix that I need to make sure 我该如何解决我需要确保的问题
that the guess isn't too big if you 如果你猜的话不会太大
think I'm gonna go back to where I was 认为我要回到原来的地方
with this test it simply says when 通过这个测试，它只是说何时
guessed cube minus cube as long as it's 只要猜到立方体减去立方体
bigger than Epsilon I'm going to keep 比我要保留的Epsilon大
going through the loop if my step is too 如果我的步骤也过循环
big I could try something just below 大我可以尝试下面的东西
cubed but not have it work and then go 立方体，但没有工作，然后去
pass cube and keep going further and 通过多维数据集，并继续前进，
further on that needs I need to says I 关于这个需求，我需要说我
need to make a change here so I want to 需要在这里进行更改，所以我想
make sure that my guess is still small 确保我的猜测仍然很小
enough and if I make that small change 够了，如果我做了那么小的改变
which I'm going to do over here 我要在这里做
and guess less than or equal to cube I 并猜测小于或等于立方体I
should be in a little bit better shape I 我应该处于更好的状态
can still run the same one but now if I 仍然可以运行相同的，但现在如果我
change increment 2/10 and run that it 更改增量2/10并运行它
gave me a solution not a very good one 给了我一个不是很好的解决方案
but basically says I didn't find a 但基本上说我没找到
solution but at least I didn't keep 解决方案，但至少我没有坚持
running forever what was the point of 永远运行是什么意思
doing this it's not to try and trick you 这样做不是要欺骗你
it's to remind you that as you make 提醒你，当你做
changes to the code you need to think 更改您需要考虑的代码
about the consequences and this was one 关于后果，这是一个
where my test wasn't capturing all of 我的测试没有涵盖所有
the cases so what can I say about this 案件，那么我能对此说些什么
particular algorithm the step could be 步骤可能是特定算法
any small number if it's too small 太小了
it's going to take a long time but as we 这将需要很长时间，但随着我们
just saw if it's too large and I'm not 只是看它是否太大而我不是
careful it could skip over the answer 小心可能会跳过答案
without getting close enough at least in 至少没有足够接近
this case I stopped rather than running 这种情况下我停下来而不是跑步
forever in general it's going to take X 总的来说，它将永远用X
divided by step number of times through 除以步骤次数
the code to find a solution and so 查找解决方案的代码等
clearly as I make step smaller and 当我将步调减小时，
smaller is going to increase the number 较小会增加数量
of steps and I'd like to find a more 的步骤，我想找到更多
efficient way to solving this problem 解决这个问题的有效方法