解題語言不限Java
- Advent of Code Day 1 逆向驗證碼
- Advent of Code Day 2 損壞校驗和
- Advent of Code Day 3 螺旋內存
- Advent of Code Day 4 高熵密碼
- Advevnt of Code Day 5 曲折的蹦床迷宮
- Advent of Code Day 6 內存重分配
- Advent of Code Day 7 遞歸馬戲團
- Advent of Code Day 8 注冊表愛好者
- Advent of Code Day 9 流處理
- Advent of Code Day 10 結哈希
- Advent of Code Day 11 六邊形迷宮
題目內容
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.
在圣誕節(jié)前夺溢,一個圣誕老人的精靈急匆匆的來叫你是己。“打印機壞了,那個淘氣排行給打不出來了”撮执。當你到了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!
當你眼中的世界重新變得清晰之后,你發(fā)現(xiàn)事物分辨率都變低缆巧,和像素一樣布持。她大概把你傳送到電腦里了吧。你查看系統(tǒng)時鐘陕悬,還有25毫秒就到午夜了题暖。在這之前,你需要收集所有55個星星捉超。每當你解決一個問題胧卤,就能收集一個星星。每 毫秒天 會有兩個問題發(fā)布拼岳。第二個問題會在第一個問題解決之后發(fā)布枝誊,祝你好運。
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燈標著“數(shù)字化檢疫”叶撒。唯一的門是鎖著的,但是有個小的面板耐版,上面寫著 “限制區(qū)祠够,禁止數(shù)字化用戶進入”,這意味著你唯一的出路是解決一個驗證碼來證明你不是一個人,事實上你只有毫秒來解決這個問題粪牲,普通人是不可能完成的古瓤。但是這對你來說好像一個小時長。
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.
這個驗證碼要求你去檢查一段數(shù)字(你的問題輸入)同時找到所有有效數(shù)字的和(有效數(shù)據(jù)是這個數(shù)字有一個相鄰的相同數(shù)字)。這段數(shù)字是循環(huán)的穿香,所以最后一個數(shù)字的下一個是第一個數(shù)字。
For example:
-
1122
produces a sum of3
(1
+2
) because the first digit (1
) matches the second digit and the third digit (2
) matches the fourth digit.
數(shù)字1122
會得到和3
(1
+2
) 皮获,因為第一個字符和第二個字符一樣纹冤,第三個和第四個一樣魔市。所以和是3。 -
1111
produces4
because each digit (all1
) matches the next.
數(shù)字1111
會得到和4
赵哲,因為所有位都是一樣的待德。 -
1234
produces0
because no digit matches the next.
數(shù)字1234
會得到和0
枫夺,因為沒有位都是是有效數(shù)字。 -
91212129
produces9
because the only digit that matches the next one is the last digit,9
.
數(shù)字91212129
會得到和9
橡庞,因為只有9
是有效數(shù)字
解題思路
day 1 的題目比較簡單较坛,所以解題不會很詳細
首先讀題
要找兩個連續(xù)的相同位數(shù)
于是用for
循環(huán)查字符串中相應位置的char
如果相等就加這個數(shù)到一個變量里。