原文地址

原文链接

前言

今天在谷歌的时候,突然弹出了游戏邀请,点进去会发现进入一个Linux系统,并且给了一些基本命令

Use the following shell commands:cd  change directory [dir_name]
cat print file [file_name]
deleteme    delete all of your data associated with foobar
edit    open file in editor [file_name]
feedback    provide feedback on foobar
less    print a file a page at a time [file_name]
ls  list directory contents [dir_name]
request request new challenge
status  print progress
submit  submit final solution file for assessment [file_name]
verify  runs tests on solution file [file_name]Keyboard help:Ctrl + S  save the open file [when editor is focused]
Ctrl + E   close the editor [when editor is focused]Toggle between the editor and terminal using ESC followed by TAB, then activate with ENTER.

以及一个小故事

Success! You've managed to infiltrate Commander Lambda's evil organization, and finally earned yourself an entry-level position as a Minion on their space station. From here, you just might be able to subvert Commander Lambda's plans to use the LAMBCHOP doomsday device to destroy Bunny Planet. Problem is, Minions are the lowest of the low in the Lambda hierarchy. Better buck up and get working, or you'll never make it to the top...

起初我以为是什么智力小游戏,在系统里面解密什么的结果使用request后,还是码代码

附上网站,不过需要邀请就是了,可能是在某个时间段触发某个搜索关键词可以收到邀请

解决方案

re-id

第一题是

Re-ID
=====There's some unrest in the minion ranks: minions with ID numbers like "1", "42", and other "good" numbers have been lording it over the poor minions who are stuck with more boring IDs. To quell the unrest, Commander Lambda has tasked you with reassigning everyone new random IDs based on a Completely Foolproof Scheme. Commander Lambda has concatenated the prime numbers in a single long string: "2357111317192329...". Now every minion must draw a number from a hat. That number is the starting index in that string of primes, and the minion's new ID number will be the next five digits in the string. So if a minion draws "3", their ID number will be "71113". Help the Commander assign these IDs by writing a function solution(n) which takes in the starting index n of Lambda's string of all primes, and returns the next five digits in the string. Commander Lambda has a lot of minions, so the value of n will always be between 0 and 10000.Languages
=========To provide a Java solution, edit Solution.java
To provide a Python solution, edit solution.pyTest cases
==========
Your code should pass the following test cases.
Note that it may also be run against hidden test cases not shown here.-- Java cases --
Input:
Solution.solution(0)
Output:23571Input:
Solution.solution(3)
Output:71113-- Python cases --
Input:
solution.solution(0)
Output:23571Input:
solution.solution(3)
Output:71113Use verify [file] to test your solution and see how it does. When you are finished editing your code, use submit [file] to submit your answer. If your solution passes the test cases, it will be removed from your home folder.

解决方案

class KotomiApplicationTests {    public static String solution(int n) {if (0 == n) {return "23571";}//build prime arrint primaryCount = 3 * n + 20;boolean[] prime = new boolean[primaryCount];//initprime[2] = true;for (int count = 1; count < primaryCount; count = count + 2) {prime[count] = true;}//Sieve of Eratosthenesint maxCount = (int) Math.sqrt(primaryCount);int count = 3;while (count <= maxCount) {for (int result = count * count; result < primaryCount; result += 2 * count) {if (prime[result]) {prime[result] = false;}}do {count += 2;} while (count <= maxCount && !prime[count]);}//readArrayDeque<Integer> primDeque = new ArrayDeque<>();primDeque.add(2);primDeque.add(3);primDeque.add(5);primDeque.add(7);primDeque.add(11);int length = 0;int curNum = 12;int lastNum = 0;while (length < n) {if (prime[curNum]) {primDeque.addLast(curNum);lastNum = primDeque.removeFirst();length += String.valueOf(lastNum).length();}++curNum;}StringBuilder str = new StringBuilder().append(lastNum);while (!primDeque.isEmpty()) {str.append(primDeque.removeFirst());}int startIndex = String.valueOf(lastNum).length() - length + n;return str.substring(startIndex, startIndex + 5);}
}

逻辑上比较简单,将素数标记,然后使用滑动窗口即可,代码应该还有可以优化的部分,如果小伙伴们有更好的解决方案可以在评论区提供

elevator-maintenance

Elevator Maintenance
====================You've been assigned the onerous task of elevator maintenance -- ugh! It wouldn't be so bad, except that all the elevator documentation has been lying in a disorganized pile at the bottom of a filing cabinet for years, and you don't even know what elevator version numbers you'll be working on. Elevator versions are represented by a series of numbers, divided up into major, minor and revision integers. New versions of an elevator increase the major number, e.g. 1, 2, 3, and so on. When new features are added to an elevator without being a complete new version, a second number named "minor" can be used to represent those new additions, e.g. 1.0, 1.1, 1.2, etc. Small fixes or maintenance work can be represented by a third number named "revision", e.g. 1.1.1, 1.1.2, 1.2.0, and so on. The number zero can be used as a major for pre-release versions of elevators, e.g. 0.1, 0.5, 0.9.2, etc (Commander Lambda is careful to always beta test her new technology, with her loyal henchmen as subjects!).Given a list of elevator versions represented as strings, write a function solution(l) that returns the same list sorted in ascending order by major, minor, and revision number so that you can identify the current elevator version. The versions in list l will always contain major numbers, but minor and revision numbers are optional. If the version contains a revision number, then it will also have a minor number.For example, given the list l as ["1.1.2", "1.0", "1.3.3", "1.0.12", "1.0.2"], the function solution(l) would return the list ["1.0", "1.0.2", "1.0.12", "1.1.2", "1.3.3"]. If two or more versions are equivalent but one version contains more numbers than the others, then these versions must be sorted ascending based on how many numbers they have, e.g ["1", "1.0", "1.0.0"]. The number of elements in the list l will be at least 1 and will not exceed 100.Languages
=========To provide a Python solution, edit solution.py
To provide a Java solution, edit Solution.javaTest cases
==========
Your code should pass the following test cases.
Note that it may also be run against hidden test cases not shown here.-- Python cases --
Input:
solution.solution(["1.11", "2.0.0", "1.2", "2", "0.1", "1.2.1", "1.1.1", "2.0"])
Output:0.1,1.1.1,1.2,1.2.1,1.11,2,2.0,2.0.0Input:
solution.solution(["1.1.2", "1.0", "1.3.3", "1.0.12", "1.0.2"])
Output:1.0,1.0.2,1.0.12,1.1.2,1.3.3-- Java cases --
Input:
Solution.solution({"1.11", "2.0.0", "1.2", "2", "0.1", "1.2.1", "1.1.1", "2.0"})
Output:0.1,1.1.1,1.2,1.2.1,1.11,2,2.0,2.0.0Input:
Solution.solution({"1.1.2", "1.0", "1.3.3", "1.0.12", "1.0.2"})
Output:1.0,1.0.2,1.0.12,1.1.2,1.3.3Use verify [file] to test your solution and see how it does. When you are finished editing your code, use submit [file] to submit your answer. If your solution passes the test cases, it will be removed from your home folder.

这题似乎比上题更简单,直接使用一个小顶堆,然后自定义排序方法即可

class KotomiApplicationTests {//jdk8public static Comparator<String> comparator = (str1, str2) -> {List<Integer> str1Arr = new java.util.ArrayList<>(Arrays.stream(str1.split("\\.")).map(Integer::valueOf).toList());List<Integer> str2Arr = new java.util.ArrayList<>(Arrays.stream(str2.split("\\.")).map(Integer::valueOf).toList());while (str1Arr.size() < 3) {str1Arr.add(-1);}while (str2Arr.size() < 3) {str2Arr.add(-1);}for (int count = 0; count < 3; ++count) {int res = str1Arr.get(count) - str2Arr.get(count);if (0 != res) {return res;}}return 0;};public static String[] solution(String[] l) {String[] ans = new String[l.length];PriorityQueue<String> leap = new PriorityQueue<>(comparator);leap.addAll(Arrays.asList(l));int count = 0;while (!leap.isEmpty()) {ans[count] = leap.poll();++count;}return ans;}
}

还有jdk17的实现,由于我是使用的17就顺便贴上了

class KotomiApplicationTests {//jdk17public static Comparator<String> comparator = (str1, str2) -> {List<Integer> str1Arr = new java.util.ArrayList<>(Arrays.stream(str1.split("\\.")).map(Integer::valueOf).toList());List<Integer> str2Arr = new java.util.ArrayList<>(Arrays.stream(str2.split("\\.")).map(Integer::valueOf).toList());while (str1Arr.size() < 3) {str1Arr.add(-1);}while (str2Arr.size() < 3) {str2Arr.add(-1);}for (int count = 0; count < 3; ++count) {int res = str1Arr.get(count) - str2Arr.get(count);if (0 != res) {return res;}}return 0;};public static String[] solution(String[] l) {String[] ans = new String[l.length];PriorityQueue<String> leap = new PriorityQueue<>(comparator);leap.addAll(Arrays.asList(l));int count = 0;while (!leap.isEmpty()) {ans[count] = leap.poll();++count;}return ans;}
}

hey-i-already-did-that

Hey, I Already Did That!
========================Commander Lambda uses an automated algorithm to assign minions randomly to tasks, in order to keep minions on their toes. But you've noticed a flaw in the algorithm -- it eventually loops back on itself, so that instead of assigning new minions as it iterates, it gets stuck in a cycle of values so that the same minions end up doing the same tasks over and over again. You think proving this to Commander Lambda will help you make a case for your next promotion. You have worked out that the algorithm has the following process: 1) Start with a random minion ID n, which is a nonnegative integer of length k in base b
2) Define x and y as integers of length k.  x has the digits of n in descending order, and y has the digits of n in ascending order
3) Define z = x - y.  Add leading zeros to z to maintain length k if necessary
4) Assign n = z to get the next minion ID, and go back to step 2For example, given minion ID n = 1211, k = 4, b = 10, then x = 2111, y = 1112 and z = 2111 - 1112 = 0999. Then the next minion ID will be n = 0999 and the algorithm iterates again: x = 9990, y = 0999 and z = 9990 - 0999 = 8991, and so on.Depending on the values of n, k (derived from n), and b, at some point the algorithm reaches a cycle, such as by reaching a constant value. For example, starting with n = 210022, k = 6, b = 3, the algorithm will reach the cycle of values [210111, 122221, 102212] and it will stay in this cycle no matter how many times it continues iterating. Starting with n = 1211, the routine will reach the integer 6174, and since 7641 - 1467 is 6174, it will stay as that value no matter how many times it iterates.Given a minion ID as a string n representing a nonnegative integer of length k in base b, where 2 <= k <= 9 and 2 <= b <= 10, write a function solution(n, b) which returns the length of the ending cycle of the algorithm above starting with n. For instance, in the example above, solution(210022, 3) would return 3, since iterating on 102212 would return to 210111 when done in base 3. If the algorithm reaches a constant, such as 0, then the length is 1.Languages
=========To provide a Java solution, edit Solution.java
To provide a Python solution, edit solution.pyTest cases
==========
Your code should pass the following test cases.
Note that it may also be run against hidden test cases not shown here.-- Java cases --
Input:
Solution.solution('210022', 3)
Output:3Input:
Solution.solution('1211', 10)
Output:1-- Python cases --
Input:
solution.solution('1211', 10)
Output:1Input:
solution.solution('210022', 3)
Output:3Use verify [file] to test your solution and see how it does. When you are finished editing your code, use submit [file] to submit your answer. If your solution passes the test cases, it will be removed from your home folder.

同样比较简单,双指针判圈

class KotomiApplicationTests {    static String iteratorMethod(String num, int b) {String small = num.chars().sorted().collect(StringBuffer::new, StringBuffer::appendCodePoint, StringBuffer::append).toString();String big = num.chars().sorted().collect(StringBuffer::new, StringBuffer::appendCodePoint, StringBuffer::append).reverse().toString();StringBuilder target = new StringBuilder(Integer.toString(Integer.parseInt(big, b) - Integer.parseInt(small, b), b));while (target.length() < num.length()) {target.insert(0, "0");}return target.toString();}public static int solution(String n, int b) {String slowPtr = iteratorMethod(n, b);String fastPtr = iteratorMethod(iteratorMethod(n, b), b);//floydwhile (!slowPtr.equals(fastPtr)) {slowPtr = iteratorMethod(slowPtr, b);fastPtr = iteratorMethod(iteratorMethod(fastPtr, b), b);}fastPtr = n;while (!slowPtr.equals(fastPtr)) {slowPtr = iteratorMethod(slowPtr, b);fastPtr = iteratorMethod(fastPtr, b);}String startPtr = fastPtr;//lengthint length = 1;slowPtr = iteratorMethod(slowPtr, b);while (!slowPtr.equals(startPtr)) {slowPtr = iteratorMethod(slowPtr, b);++length;}return length;}
}

这样前两关就基本完事了,之后的题目得空再玩吧

Level 2 complete
You are now on level 3
Challenges left to complete level: 3Level 1: 100% [==========================================]
Level 2: 100% [==========================================]
Level 3:   0% [..........................................]
Level 4:   0% [..........................................]
Level 5:   0% [..........................................]

原文地址

原文链接

GoogleFoobarCode邀请挑战前篇相关推荐

  1. 计算机学院邀请函,关于邀请学校邀请函五篇

    关于邀请学校邀请函五篇 邀请函要符合礼仪文书的行文要求,追求事务与礼仪的完美结合.在我们平凡的日常里,各种邀请函频频出现,想必许多人都在为如何写好邀请函而烦恼吧,以下是小编整理的邀请学校邀请函6篇,仅 ...

  2. Boosted Tree:一篇很有见识的文章

    Boosted Tree:一篇很有见识的文章 6,125 次阅读 - 文章 作者:陈天奇,毕业于上海交通大学ACM班,现就读于华盛顿大学,从事大规模机器学习研究. 注解:truth4sex  编者按: ...

  3. 400是什么错误_我想对您说小学作文400字7篇

    老师,我想对您说,谢谢您!老师您就像一盏明灯,照耀着我们前方的道路;您就像一本书,脑袋里藏着许多知识;您就像一台电脑,教给我们许多知识.现在,我不得不说感谢您.下面就是小编给大家带来的我想对您说作文, ...

  4. 这是一篇有温度的NLP秋招面经

    一.前言 往昔的回忆使我们激动,我们重新踏上旧日的路,一切过去日子的感情,又逐渐活在我们的心里:使我们再次心紧的是,曾经熟悉的震颤:为了回忆中的忧伤,真想吐出一声长叹--感谢一路上曾经鼓励.帮助过我的 ...

  5. 怎么写一篇计算机SCI论文初稿? - 易智编译EaseEditing

    一.SCI论文的要求 SCI论文的核心是创新性.对于这个方面来说主要就是针对于论文的观点正确,文字通畅,逻辑严密,结构合理,结论有创新等等. 二.SCI论文格式规范 每一个SCI期刊都有自己特定的宗旨 ...

  6. IOS开发高手课第一篇 构建自己的IOS开发知识体系

    开篇词 | IOS开发锚定一个点,然后在这个点上深耕 你好,我是戴铭,欢迎你加入我的 iOS 开发专栏. 说起 iOS 开发,自然是绕不开 iPhone 和 App Store 这两个词.多少年过去了 ...

  7. 如何将深度学习研究论文实现为代码的几个要点

    点击上方"3D视觉工坊",选择"星标" 干货第一时间送达 作者:Bipin Krishnan P 编译:ronghuaiyang 导读 如果深度学习是一种超能力 ...

  8. 计算机视觉方向博士科研学习总结 拜读

    转载来源:https://blog.csdn.net/gdengden/article/details/80365518 入门一年多来的心路历程 2016.11~2017.3 时间倒回到大二上,那会就 ...

  9. 他曾经复读才考上三本,如今让华为开出201万年薪(其实还拒绝了360万offer)...

    萧箫 鱼羊 发自 凹非寺 转载自量子位 他叫张霁,1993年生于湖北,最近以入选华为「天才少年」计划被人熟知. 因为27岁的他,拿到了华为最高201万的年薪offer. 一开始被认知,他是华中科技大学 ...

  10. 博士生AI岗位面试经验分享:这样可以让您的薪水翻一倍

    [导读]本文作者根据自己博士毕业后求职.面试的经历,从重要资源.公司.面试过程.薪资谈判等方面详细的介绍并分享了自我体会与经验.看完本文,你会对求职有一个深入的体会! 本文作者刚刚完成博士学位,并在所 ...

最新文章

  1. mongoTemplate 条件查询
  2. java实现单向链表
  3. RHEL 5.4 安装Oracle 11gR2, 准备篇...
  4. 【视频课】图像分割最新内容来了(言有三新录制6大理论部分+1个案例实践讲解)...
  5. 10深入理解C指针之---指针运算和比较
  6. 三种常见的SQL分页语句
  7. 斐讯k1潘多拉专版固件_斐讯K1刷专版潘多拉固件以及教程(使用感受)
  8. 内核常见锁的机制与实现分析1
  9. Android动态壁纸画布透明,Android 动态壁纸LayoutParams问题
  10. cad图纸批量转换pdf
  11. 如何玩转YouTube
  12. 1222-周一开盘红红火火大涨的一天。EG,PVC,沪铜,国际铜,纯碱涨停
  13. JavaScript:实现multiplesThreeAndFive三或五倍数的算法 (附完整源码)
  14. ofbiz——工作流学习笔记一(xpdl)
  15. Reader/Writer字符流概述和使用方法
  16. 为什么大数据工程师比Java程序员工资高
  17. Scala 继承和特质
  18. java获取汉字拼音_Java获取汉字对应的拼音(全拼或首字母)
  19. 二叉树的遍历(前序、中序、后序、层次)
  20. 来自飞机座椅的实测数据

热门文章

  1. 海量数据解决思路之Hash算法
  2. resnet50 尝试 pytorch-grad-cam
  3. 入栏需看——管理类联考——英语——知识+记忆篇——导航页
  4. samba的挂载语法
  5. C#基础加强题目和代码
  6. 关于软件“跑跑”的使用体验
  7. [筹婚八卦] 两个好人,却没有好婚姻
  8. 项目管理中影响项目进度的原因及解决方法
  9. 【灯塔】11.8总结
  10. CSP2019 初赛 翘课记