绝地求生米拉马延迟高

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. 2012年4月当选微软MVP的CSDN会员名单揭晓!
  2. 搜java题的公众号_java搜题公众号
  3. 服务机器人平台和后台
  4. Codeforces Round #324 (Div. 2) B. Kolya and Tanya
  5. 详解中奖概率逻辑:为什么你中不了特等奖(附原件)
  6. STL源码学习之空间配置
  7. java hashset 实现_HashSet实现原理分析(Java源码剖析)
  8. PHP和javascript中url编码解码详解
  9. IGMC,Inductive graph-based matrix completion,基于归纳图的矩阵完成
  10. iOS蓝牙开发(三)实现外设功能
  11. 超级推荐!!值得收藏的黑客系列书:《黑客攻防实战xx》系列图书简介,一共4本
  12. 计算机基础知识思维导图怎么画,怎样在计算机中绘制思维导图的操作过程分享...
  13. 可爱的HOOk技术(一)
  14. 从杂技表演到日剧GBM(r12笔记第23天)
  15. 测试投入度量元的选择
  16. leetcode | 整数反转
  17. 机器学习入门——简单线性回归
  18. 定了!自考还没有报名的每人补贴8000元!政策扶持,名额有限,速看!!!!...
  19. 读取OSGB数据的几种方式
  20. 手机如何制作gif?简单三步在线合成gif动图

热门文章

  1. Linux运维工程师中级面试题
  2. 树莓派卸载python2.7_树莓派上的软件安装和卸载命令汇总
  3. 海汽集团:业财共享服务中心建设推进集团数字治理
  4. Java getMethod与invoke的使用
  5. Dell-R710服务器硬盘阵列配置
  6. 网上开具个人所得税纳税记录
  7. WebLogic 重置域控制台账号密码
  8. 老程序员教你如何提高开发效率、成为大神6——程序的本质
  9. js map满足条件跳出循环_js for等循环 跳出多层循环
  10. 无锡校长另类“励志”演讲:长得不帅还不学习