绝地求生米拉马延迟高

by Geoffrey Bourne

杰弗里·伯恩(Geoffrey Bourne)

知道无限的人:编码拉马努詹的出租车 (The Man Who Knew Infinity: Coding Ramanujan’s Taxi)

Have you see the movie (or read the book) The Man Who Knew Infinity?

您看过电影(或看过书) 《无尽的男人》吗?

This new movie — which stars Dev Patel and Jeremy Irons — explores Indian mathematician Srinivasa Ramanujan and his profound understanding, ingenuity, and love of math.

这部新电影由戴维·帕特尔(Dev Patel)和杰里米·艾恩斯(Jeremy Irons)饰演,探讨了印度数学家Srinivasa Ramanujan及其对数学的深刻理解,独创性和热爱。

The film inspired me on both an intellectual and emotional level. But what really drew my attention was a particular five second scene.

这部电影在思想和情感上都启发了我。 但是真正引起我注意的是一个特定的五秒钟场景。

The scene takes place in 1918. Ramanujan‘s mentor and friend G.H. Hardy quips that he had just taken taxi number 1729 and finds the number “a rather dull one.”

现场发生在1918年。拉马努詹的良师益友GH Hardy嘲笑他刚乘过1729号出租车,发现这个号码“相当呆板”。

Ramanujan passionately replies, “No, Hardy, it’s a very interesting number! It’s the smallest number expressible as the sum of two cubes in two different ways.”

Ramanujan热情地回答:“不,Hardy,这是一个非常有趣的数字! 它是用两种不同方式表示为两个多维数据集之和的最小数字。”

Ramanujan was able to see beyond the simple taxi cab number and into the depths of the expression behind it: a³ + b³ = c³ + d³…better known as Ramanujan’s Taxi. I thought this problem was fascinating and wondered how the code implementation would look. Little did I realize there were many optimization layers to this algorithm onion.

Ramanujan不仅可以看到简单的出租车号码,还可以看到其背后的表情:a³+b³=c³+d³………更被称为Ramanujan的出租车 。 我认为这个问题令人着迷,并想知道代码实现的外观。 我几乎没有意识到该算法洋葱有很多优化层。

实施Ramanujan出租车的第一步 (First Crack at Implementing Ramanujan’s Taxi)

I started with a straight forward implementation written in Scala. The code, with performance timings, can be found on GitHub:

我从使用Scala编写的直接实现开始。 带有性能计时的代码可以在GitHub上找到 :

We begin with a brute-force implementation by looping though all combinations to find where a³ + b³ = c³ + d³. We achieve O(n⁴) performance because of the four loops used to calculate all values of a³, b³, c³, and d³ equal or less than parameter n, which bounds our search field.

我们通过循环遍历所有组合以找出a³+b³=c³+d³的方式开始于蛮力实施。 由于四个循环用于计算等于或小于参数n的所有a³,b³,c³和d³值,因此我们实现了O(n⁴)性能,这限制了我们的搜索范围。

This brute-force implementation, with O(n⁴) performance, kinda sucks. So, how can we do better?

这种具有O(n⁴)性能的强力实现有点糟。 那么,我们如何才能做得更好?

我们可以做得更好 (We Can Do Better)

First question to ask is: do we always need to calculate all the values of a³, b³, c³, and d³? Remember, the equation we are using is a³ + b³ = c³ + d³. If we solve for d³, we get d³ = a³ + b³ - c³. Thus, once we know a³, b³, and c³, we can calculate the value of d³ directly instead looping through all values of d³.

首先要问的是:我们是否总是需要计算a³,b³,c³和d³的所有值? 记住,我们使用的方程是a³+b³=c³+d³。 如果求解d³,则得到d³=a³+b³-c³。 这样,一旦我们知道a³,b³和c³,就可以直接计算d³的值,而不必遍历所有d³的值。

My next implementation, again in Scala, replaces the fourth loop with the calculation d³ = a³ + b³ — c³:

我的下一个实现也是在Scala中,用计算值d³=a³+b³—c³代替了第四个循环:

The 2nd version has O(n³) performance since we get to skip that final loop. Neat!

由于我们跳过了最后一个循环,因此第二个版本具有O(n³)性能。 整齐!

第三次魅力 (Third Time’s A Charm)

We’re not done yet. There is a third, and the best yet, enhancement to consider. What if we don’t need to solve for all values of not only d³, but c³ too? A few things to understand:

我们还没有完成。 需要考虑的第三项也是最好的增强。 如果我们不仅需要求解d³,还需要求解c³的所有值,该怎么办? 需要了解的几件事:

  1. If we calculate all values of a³ and b³ equal to or less than n, we essentially have all possible values of not only a³ and b³, but also c³ and d³.如果我们计算出所有等于或小于n的a³和b³值,那么我们实际上不仅具有a³和b³的所有可能值,而且还具有c³和d³的所有可能值。
  2. The sum of a³ + b³ is equal to the sum of c³ + d³a³+b³之和等于c³+d³之和
  3. If the sum of #2 above for a given pair of integers (a³, b³) matches the sum of another pair of integers (a³, b³), we have in essence found the c³ and d³ pair.如果对于给定的一对整数(a³,b³),上面#2的总和与另一对整数(a³,b³)的总和相匹配,则我们实际上找到了c³和d³对。

If we store every combination of the sum of a³ + b³ and the corresponding pair (a³, b³), any sum that has two pairs means we have found a³ + b³ = c³ + d³ where the first pair in the list can be considered (a³, b³) and the next (c³, d³).

如果我们存储a³+b³和与之对应的对(a³,b³)的每种组合,则任何具有两对的和都意味着我们找到a³+b³=c³+d³,可以将列表中的第一对视为( a³,b³)和下一个(c³,d³)。

For example, if we iterate through the combinations of a³ + b³, we will store the sum 1729 with the pair (1³, 12³). Continuing to iterate, we will see another sum of 1729 arise, but this time with the pair (9³, 10³). Because we have two different pairs both summing to 1729, we have found a Ramanujan Taxi that solves for a³ + b³ = c³ + d³.

例如,如果我们遍历a³+b³的组合,则将和1729与对(1³,12³)存储在一起。 继续进行迭代,我们将看到又产生了1729,但这次是货币对(9³,10³)。 因为我们有两个不同的货币对,总和为1729,所以我们找到了拉曼努(Ramanujan)出租车,可以解决a³+b³=c³+d³。

In the third version, we use a Hashmap to store the sum (key) and the corresponding list of pairs as a Sorted Set (value). If the list contains more than one pair, we’ve got a winner!

在第三个版本中,我们使用Hashmap将总和(键)和相应的对列表存储为排序集(值)。 如果列表中包含一对以上,我们就有赢家了!

This implementation has O(n²) performance since we only need two loops to calculate the combinations for a³ and b³. Very neat!

此实现具有O(n²)性能,因为我们只需要两个循环即可计算a³和b³的组合。 井井有条!

I suspect there is a forth optimization where we only need to calculate values of a³ and derive b³ from a³ (the ‘b’ loop is just an offset of the ‘a’ loop) with O(n) performance.

我怀疑有第四种优化方法,我们只需要计算a³的值并从a³得出b³(“ b”循环只是“ a”循环的偏移量),其性能为O(n)。

Also, another challenge is to re-write the implementations as a functional programming pattern. I’ll leave that for you to explore.

另外,另一个挑战是将实现重新编写为功能编程模式。 我将其留给您探索。

一部了不起的电影,一个了不起的人 (An Amazing Movie, an Amazing Man)

After watching The Man Who Knew Infinity, I was in awe of Ramanujan’s genius. By implementing his taxi algorithm — with its several performance optimizations — I got a glimpse of the beauty he saw in “No, Hardy, it’s a very interesting number!”

看完《知道无限的人》之后,我对拉马努詹的天才敬畏。 通过实施他的滑行算法及其多项性能优化,我瞥见了他在“不,哈代,这是一个非常有趣的数字!”中看到的美丽。

Ramanujan’s Taxi, at almost a century old, is still making new discoveries. Mathematicians at Emory University have found the number 1729 relates to elliptic curves and K3 surfaces — objects important today in string theory and quantum physics.

Ramanujan的的士已有近一个世纪的历史,仍在不断发现新发现。 埃默里大学的数学家们发现数字1729与椭圆曲线和K3曲面有关,而椭圆曲线和K3曲面是当今弦论和量子物理学中的重要对象。

I expect we have only scratched the surface of Ramanujan’s taxi cab number and the man’s amazing genius.

我希望我们只涉及Ramanujan的出租车号码和该男子的惊人天才的表面。

About the Author: Geoffrey Bourne is the CEO of RETIRETY — helping people in or near retirement find a better way to retire.

作者简介: Geoffrey Bourne是RETIRETY的首席执行官-帮助退休或接近退休的人们找到更好的退休方式。

谢谢阅读! (Thanks for reading!)

如果您喜欢这篇文章,请随时点击下面的鼓掌按钮? 帮助别人找到它! (If you enjoyed this article, feel free to hit that clap button below ? to help others find it!)

翻译自: https://www.freecodecamp.org/news/the-man-who-knew-infinity-coding-ramanujans-taxi-52e4c3696e53/

绝地求生米拉马延迟高

绝地求生米拉马延迟高_知道无限的人:编码拉马努詹的出租车相关推荐

  1. w10自动删除文件怎么关了_绝地求生怎么删除新地图_删新沙漠地图文件办法

    绝地求生怎么删除新地图?对于这张沙漠地图来说,很多玩家都不喜欢,大家都觉得掩体太少了,很容易死不好玩,还是比较喜欢老地图,怎么才能删除这张沙漠地图,从而不会匹配到呢?下面安卓市场小编就为各位玩家带来绝 ...

  2. 吃鸡是服务器好还是i系列好,绝地求生服务器区别是什么_各个服务器有什么特点...

    绝地求生服务器区别是什么?各个服务器有什么特点?不少玩家已经都想要换服,不知道哪些服务器比较好玩,比较适合自己,下面就和安卓市场小编来了解一下吧. 亚服:地狱难度.挂多.LYB多.各种莫名其妙就躺下最 ...

  3. 绝地求生北美服务器延迟过高,《绝地求生》匹配系统出错延迟过高 官方正加紧修正...

    <绝地求生>匹配系统出错延迟过高 官方正加紧修正 2018-10-13 07:27:53来源:游戏下载编辑:评论(0) 今天,<绝地求生>官方微博@PUBG_STEAM发布了一 ...

  4. 绝地求生哪个服务器延迟,绝地求生:腾讯公布国服服务器,超性能环境绝对稳定远离延迟!...

    原标题:绝地求生:腾讯公布国服服务器,超性能环境绝对稳定远离延迟! <绝地求生>国服似乎离我们越来越近了,在之前的审核阶段,就有消息称由于为了过审,提交审核的游戏版本是之前的测试版,所以国 ...

  5. 绝地求生服务器延迟检测源码,绝地求生不停网络延迟检测怎么办 绝地求生网络问题解决办法...

    每个游戏玩家在游戏中都会遇到延迟卡顿的现象,最近许多朋友在玩绝地求生的时候出现一直网络延迟检测,这是怎么回事呢?下面小编介绍一下解决的办法,让你们畅快的吃鸡. 1.首先设置游戏的启动项:-USEALL ...

  6. 6月3号绝地求生服务器维护,绝地求生6月3日维护到几点_2020年6月3日绝地求生更新维护开服时间介绍_咖绿茵手游站...

    绝地求生6月3日维护到几点呢,2020年6月3日绝地求生对正式服进行停机维护,接下来就让咖绿茵小编给大家带来<绝地求生>6月3日更新维护开服时间介绍. <绝地求生>6月3日更新 ...

  7. wifi卡慢延迟高_家里WiFi特别卡,网络延迟高,可能不是网速的问题

    原标题:家里WiFi特别卡,网络延迟高,可能不是网速的问题 随着科技走向我们的身边,网络的覆盖力度也是越来越大,相信很多人的家中都是有安装WiFi的,然后往往在家中使用的过程中都会碰到这样的情况,明明 ...

  8. 绝地求生游戏总显示服务器崩溃,绝地求生总是游戏崩溃怎么办_绝地求生游戏崩溃解决办法_绝地求生_我爱秘籍...

    相信有很多网友在玩绝地求生时总是出现游戏崩溃的现象,但是又不知道该如何解决.下面小编为大家带来绝地求生游戏崩溃解决办法,希望对大家有所帮助. 内容来源:PUBG官博 绝地求生游戏崩溃解决办法 部分玩家 ...

  9. 绝地求生信号枪在哪个服务器,绝地求生信号枪位置_绝地求生信号枪刷新地点介绍_游戏吧...

    绝地求生游戏中有很多的小伙伴们都想知道信号枪位置在哪,下面游戏吧小编为大家带来绝地求生信号枪刷新地点介绍,感兴趣的玩家们快来一起了解一下吧! 绝地求生信号枪位置介绍 固定刷新点这把枪将会改变大部分人的 ...

最新文章

  1. 360金融携手上海交大共建AI实验室,开启人才战略新布局
  2. Linux常用命令及技巧2
  3. Go语言中如何进行测试
  4. 开学测试代码——需求征集系统
  5. docker与虚拟机性能比较
  6. python+pytest接口自动化_python接口自动化11-pytest入门
  7. Angr安装与使用之使用篇(四)
  8. ROI和widthStep
  9. sir模型初始值_sir模型初始值_SIR 模型笔记
  10. 省市区随机获取 java_随机获取省市区-Groovy
  11. x86 BIOS 中断 INT 10h
  12. 对于上海交通大学网络安全专业21考研823的一些总结以及22考研专业课如何准备的想法
  13. linux离线安装netstat,在Ubuntu中安装netstat等网络工具
  14. 密码分析之单表代换原理详解与算法实现
  15. 「 神器 」快速启动应用Wox
  16. 电脑变WIFI:建立虚拟共享WIFI热点可查看WIFI密码windows中使用bat批处理命令提示符cmd创建教程含工具
  17. Java——第二次上机(第二部分)
  18. dlib重新训练dlib_face_recognition_resnet_model_v1.dat
  19. 初中级程序员进阶高级程序员,必须要了解的设计模式(45种设计模式)
  20. 华为HCIE RS笔记-20 OSPF的V-Link

热门文章

  1. linux下svn怎么查看修改记录,SVN如何查看修改的文件记录
  2. ppt2013中怎么复制粘贴无格式文本?
  3. 超多、超新的电子图书共享网站
  4. 彻底弄懂HTTP缓存机制及原理
  5. 乐视2017暑期实习生笔试题(一)
  6. 疫情患者活动轨迹查询-小程序
  7. allocator类
  8. SQL 分组统计去重有条件的过滤
  9. 感知机(perceptron)算法与模型
  10. Linux下C语言嵌入式笔记(九)--面试解析