美文网首页Advent of Code程序员
Advent of Code Day 1 逆向验证码

Advent of Code Day 1 逆向验证码

作者: 宅纸箱 | 来源:发表于2017-12-02 01:31 被阅读177次

    解题语言不限Java

    题目内容

    The night before Christmas, one of Santa's Elves calls you in a panic. "The printer's broken! We can't print the Naughty or Nice List!" By the time you make it to sub-basement 17, there are only a few minutes until midnight. "We have a big problem," she says; "there must be almost fifty bugs in this system, but nothing else can print The List. Stand in this square, quick! There's no time to explain; if you can convince them to pay you in stars, you'll be able to--" She pulls a lever and the world goes blurry.

    在圣诞节前,一个圣诞老人的精灵急匆匆的来叫你。“打印机坏了,那个淘气排行给打不出来了”。当你到了17号分基地,距离圣诞夜只有几分钟了。“这下麻烦大了”,精灵说,“差不多有50 多个bug,但是除了这个,我们也没有其他地方能打这个名单了。你站到这个格子里来,快点!没时间解释了,如果你可以说服他们用星星在付你的薪水,你可以”,她拉下拉杆,你眼前的世界变得模糊。

    When your eyes can focus again, everything seems a lot more pixelated than before. She must have sent you inside the computer! You check the system clock: 25 milliseconds until midnight. With that much time, you should be able to collect all fifty stars by December 25th. Collect stars by solving puzzles. Two puzzles will be made available on each day millisecond in the advent calendar; the second puzzle is unlocked when you complete the first. Each puzzle grants one star. Good luck!

    当你眼中的世界重新变得清晰之后,你发现事物分辨率都变低,和像素一样。她大概把你传送到电脑里了吧。你查看系统时钟,还有25毫秒就到午夜了。在这之前,你需要收集所有55个星星。每当你解决一个问题,就能收集一个星星。每 毫秒 会有两个问题发布。第二个问题会在第一个问题解决之后发布,祝你好运。

    You're standing in a room with "digitization quarantine" written in LEDs along one wall. The only door is locked, but it includes a small interface. "Restricted Area - Strictly No Digitized Users Allowed." It goes on to explain that you may only leave by solving a captcha to prove you're not a human. Apparently, you only get one millisecond to solve the captcha: too fast for a normal human, but it feels like hours to you.

    你站在一个房间里,一面墙上用LED灯标着“数字化检疫”。唯一的门是锁着的,但是有个小的面板,上面写着 “限制区,禁止数字化用户进入”,这意味着你唯一的出路是解决一个验证码来证明你不是一个,事实上你只有毫秒来解决这个问题,普通人是不可能完成的。但是这对你来说好像一个小时长。

    The captcha requires you to review a sequence of digits (your puzzle input) and find the sum of all digits that match the next digit in the list. The list is circular, so the digit after the last digit is the first digit in the list.

    这个验证码要求你去检查一段数字(你的问题输入)同时找到所有有效数字的和(有效数据是这个数字有一个相邻的相同数字)。这段数字是循环的,所以最后一个数字的下一个是第一个数字。

    For example:

    • 1122 produces a sum of 3(1+2) because the first digit (1) matches the second digit and the third digit (2) matches the fourth digit.
      数字1122会得到和 3(1+2) ,因为第一个字符和第二个字符一样,第三个和第四个一样。所以和是3。
    • 1111 produces 4 because each digit (all1) matches the next.
      数字1111会得到和 4,因为所有位都是一样的。
    • 1234produces0 because no digit matches the next.
      数字1234会得到和 0,因为没有位都是是有效数字。
    • 91212129 produces 9 because the only digit that matches the next one is the last digit, 9.
      数字91212129会得到和 9,因为只有9是有效数字

    解题思路

    day 1 的题目比较简单,所以解题不会很详细

    首先读题
    要找两个连续的相同位数
    于是用for循环查字符串中相应位置的char
    如果相等就加这个数到一个变量里。

    相关文章

      网友评论

        本文标题:Advent of Code Day 1 逆向验证码

        本文链接:https://www.haomeiwen.com/subject/koiybxtx.html