Redian新闻
>
6道题,45分钟!G-Research的科技与狠活

6道题,45分钟!G-Research的科技与狠活

财经


量化投资与机器学习微信公众号,是业内垂直于量化投资、对冲基金、Fintech、人工智能、大数据领域的主流自媒体公众号拥有来自公募、私募、券商、期货、银行、保险、高校等行业30W+关注者,荣获2021年度AMMA优秀品牌力、优秀洞察力大奖,连续2年被腾讯云+社区评选为“年度最佳作者”。


欧洲Top量化对冲基金G-Research最近举办了一个Coding Challenge。
一共有6个题,需要在45min内答完。完成挑战的选手有机会获得13寸的Mac Pro,并有机会获得G-Research的面试邀请。
QIML查看了该比赛,并与跟大家分享这6道题目,拿不拿奖不重要,让我们看看题目的难度与大家的水平~



Q1:Everyone has heard of "FizzBuzz". If you haven't: Google it. You are allowed to use the internet during this test. We'd like you to implement "FizzBuzz" please. Except at G-Research we often see the Pareto principle (or "80/20 rule") and generally believe in agile incremental delivery, so to make it easier we actually just want the Fizzes and not any Buzzes, please.


第一题一上来可能有些闷,但如果大家熟悉'FizzBuzz',意思就是给你一个整数比如100,需要你输出一个列表。列表中的每个元素,如果能背3整除则输出'Fizz',如果被5整除则输出'Buzz',如果能同时被3和5整除,则输出'FizzBuzz'。比如给出整数15,则答案是:['1', '2', 'Fizz', '4', 'Buzz', 'Fizz', '7', '8', 'Fizz', 'Buzz', '11', 'Fizz', '13', '14', 'FizzBuzz']。

但注意,本题简化了要求,只需要'Fizz', 意思是只要能被3整除就输出'Fizz',其他不用管。第一题确实非常简单。
QIML参考代码如下:
import typing

def solution(n: int) -> typing.List[str]:
    res = []
    for i in range(1, n+1):
        if i % 3 == 0 
            res.append('Fizz')
        else:
            res.append(str(i))
    return res



Q2:It was hopefully obvious this was coming. FizzBuzz, please.


第二题是让你实现一个完整的FizzBuzz。

QIML参考代码如下:
import typing

def solution(n: int) -> typing.List[str]:
    res = []
    for i in range(1, n+1):
        if i % 3 == 0 and i % 5 == 0:
            res.append('FizzBuzz')
        elif i % 3 == 0:
            res.append('Fizz')
        elif i % 5 == 0:
            res.append('Buzz')
        else:
            res.append(str(i))
    return res



Q3:We quite like prime numbers at G-Research. We also often face requirements that are unknown at the start of software engineering and have to evolve to follow where the research leads. We'd now like FizzBuzz but with the added complexity of prime numbers being preferentially emitted as "Prime".


难度逐渐提升,需要在Q2的基础上,识别质数。如果是质数,则输出为“Prime”。所以代码中我们需要新增一个判断是否为质数的Function。
QIML参考代码如下:
import typing

def is_prime(n: int) -> bool:
    if n == 1:
        return False
    else:
        for i in range(2,n):
            if n%i == 0:
                return False
        else:
            return True

def solution(n: int) -> typing.List[str]:
    res = []
    for i in range(1, n+1):
        if is_prime(i):
            res.append('Prime')
        elif i % 3 == 0 and i % 5 == 0:
            res.append('FizzBuzz')
        elif i % 3 == 0:
            res.append('Fizz')
        elif i % 5 == 0:
            res.append('Buzz')
        
        else:
            res.append(str(i))
    return res



Q4:G-Research also has an inexplicable penchant for pi. The requirements are now such that if the number being tested, represented as a decimal's present in the first p digits of pi, also represented as a decimal and ignoring any decimal point, then"Pi" is emitted preferentially to Fizzes Buzzes or Prime. e.g. if p is 3 then we test against 314 and so 3,1,4,14,31 and 314 would all return "Pi".


难度继续增加,在Q3的基础上,如果数字是Pi前n位字符串的一个连续子集,则需要输出pi。题目会给定n和p两个数字,比如n=15,p=3。那么答案是['Pi', 'Prime', 'Pi', 'Pi', 'Buzz', 'Fizz', 'Prime', '8', 'Fizz', 'Buzz', 'Prime', 'Fizz', 'Prime', 'Pi', 'FizzBuzz']。可以发现,题目中的1, 3, 4, 14都输出为"Pi", 是因为题目给定p=3,也就是说只要是314的连续子集,则对应位置的数字要输出为'Pi'。(如果p=4,则只要是3141的连续子集,则对应位置的数字要输出为'Pi')。
这一题,QIML尝试了多次后,最后一个testcase总是无法通过,主要问题就在于怎么样计算pi,因为math模块中的pi只精确到小数点后16位,当题目中p大于17时就无法使用python内置的pi。
所以本题的核心,QIML认为有以下几点:
1、如何使用Python计算任意位数的pi。
2、还有一点是需要考虑n和p之间的关系,是否存在一个值,当p大于这个值时,所有n的输出都是pi?(欢迎大家讨论与指正)
最后两题,是在Q4的基础上对p和n取超大值的一个思考:

Q5:The underlying problem is the same: FizzBuzzPrimePi. If your previous submission cannot cope with arbitrarily large input, for either input, that is now a requirement. If this seems unreasonable, optimising maximum size of n is more valuable than optimising maximum size of p. The test cases here will remain simple the quality of the code matters.




Q6:What is the minimum p such that every response is"Pi" for a given input n?


大家可以在下方留言区,聊聊对Q5\Q6的想法
挑战报名链接:https://hrd.cm/3yWPLE9

微信扫码关注该文公众号作者

戳这里提交新闻线索和高质量文章给我们。
相关阅读
那么有没有科技与狠活?中美酱油配料表对比答应我,别当科技与狠活的魔怔人了。抖音博主现场做假酒,5块钱兑出“百年陈酿”!又是科技与狠活……满满的科技与狠活!揭秘食品添加剂,是在玩命科普还是贩卖焦虑?实战的科技与狠活汇源果汁:没有科技与狠活,只有干净的配料表!希望大家理想消费【广而告之】为什么Chegg抓作弊,一抓一个准?CEO说了,这里全是科技与狠活儿国外买个麦当劳都是科技与狠活?答应我,别再傻傻地当魔怔人了。林其仁先生没有科技与狠活,包爸上新的秋冬美食必吃榜,给娃放心吃!食品中的科技与狠活?伦敦奥运会兴奋剂事件提了个醒!全是科技与狠活科技与狠活!轮胎店又亮了!多伦多高分圣诞灯展放票时间出来了科技与狠活 | 中美酱油配料表搞“双标”?食品添加剂真的那么可怕吗?对比中美酱油配料表,食品添加剂就是纯纯“科技与狠活”?魂记海天酱油,科技与狠活?2022年雅典神话之旅 8 德尔斐,神谕的地方(上)新仪器可测尿骚味:纽约地铁的科技与狠活美国有没有科技与狠活?中美酱油配料表对比科技与狠活背后的食品焦虑英文小小说初尝试(中英双语)别想了,你根本躲不开所谓的“科技与狠活”30天涨粉600W!“科技与狠活”,还让不让人活?薄而不断,卷菜不散!没有科技与狠活,只有百年相传的口碑!辛吉飞退网了,“科技与狠活”还依然存在,敲响人民重视食品安全的警钟“科技与狠活”的魔怔人只能绝食了答应我,别当科技与狠活的魔怔人了嘴里少点“科技与狠活”不靠“科技与狠活”,ta也能让你上瘾?在科技与狠活的当下,推荐这款配料不添加,健康放心的梨膏。摇一摇 就能直接喝~The Withered Rose求求了,别再用“科技与狠活”贩卖焦虑了还来科技与狠活?这几年的PPT辅助网站都在这了!没有“科技与狠活”的汇源果汁,意外翻红了
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。