如何预测数字序列即Excel?
在 Excel 中,有一个很好的功能,如果您在三个连续的单元格中输入 1、2、3,然后选择单元格并向下拖动,它会自动将其余单元格填充为 4、5、6、7 等。它还能够匹配更多的模式。例如,如果我输入 2、4、6、8,它会识别出我正在添加 2,然后建议 10、12、14 等。Excel
如何知道哪些数字?他们是否对不同的情况进行硬编码(即添加一些常量,减去一些常量,乘以一些常量)或者是否有某种算法可以自动为您预测这一点? (这个问题应该与语言无关,但如果有帮助,我想在 jQuery 中做到这一点)
谢谢!
In Excel, there is a nice feature where if you enter 1, 2, 3 in three consecutive cells and then select the cells and drag down, it automatically fills in the rest of the cells as 4, 5, 6, 7, etc. It is also able to match more patterns. For example, if I did 2, 4, 6, 8, it would recognize I am adding 2 and then suggest 10, 12, 14, etc.
How does Excel know which numbers? Do they hardcode the different cases (i.e. adding some constant, subtracting some constant, multiplying by some constant) or is there some algorithm that can automatically predict this for you? (This question should be language-agnostic, but if it helps, I want to do this in jQuery)
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我很确定这是一件简单的事情。当用户输入三个数字时,Excel 可能会检查每个连续数字之间的增量。如果两次相同,它将使用该增量来预测下一个数字。
I'm pretty sure it's a simple thing to do. Excel probably checks, when a user enters three numbers, the delta between each consecutive number. If they are the same both times, it will use that delta to predict the next number.
如果您想比 Excel 更通用地执行此操作(仅添加或减去常量值),请查看一些 从数值方法的角度来看插值算法。 这篇 wikibook 文章 是一篇不错的教程。
If you want to do this more generically than Excel does (only addition or subtraction of constant values), have a look at some interpolation algorithms from numerical methods point of view. This wikibook article is an ok tutorial.
在 Excel 中,它仅适用于加法和减法(据我所知,我只是尝试使用乘法,结果与原始结果不遵循相同的模式)。
知道了这一点,我认为计算前两个单元格之间的差异会很容易,然后检查单元格 2 和单元格 3 之间的差异,看看它是否相同。然后,您可以将该转换应用于您想要预测的单元格。
然后,您可以使用 for 循环将所需的值复制到所有选定的单元格(如果您想让接下来的 10 个单元格遵循该模式,请使用 for 或 while 循环来更新这 10 个单元格的值)
In Excel, it only works with additions and substractions (that I know of, I just tried with multiplications and the results don't follow the same pattern as the originals).
Knowing that, I think it would be easy to calculate the difference between the first two cell, then check the difference between cell 2 and cell 3 to see if it's the same. You can then apply that transformation to the cells you want to predict.
You could then use a for loop that would copy the value you want to all selected cells (if you want to make the next ten cells follow the pattern, use a for or a while loop that will update the value of those 10 cells)