解題語言不限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 11 六邊形迷宮
題目內容
An urgent interrupt arrives from the CPU: it's trapped in a maze of jump instructions, and it would like assistance from any programs with spare cycles to help find the exit.
一個從CPU來的緊急中斷到達,CPU被困在了一個跳躍的迷宮里。它需要來著空閑幫助才可以從這個迷宮里出來。
The message includes a list of the offsets for each jump. Jumps are relative: -1 moves to the previous instruction, and 2 skips the next one. Start at the first instruction in the list. The goal is to follow the jumps until one leads outside the list.
這條消息包含了一個跳躍偏移量列表。跳躍是相對的:-1 會把指針移到前一個項,2 會跳過一個。從列表的第一個開始,到跳出最后一個為止。
In addition, these instructions are a little strange; after each jump, the offset of that instruction increases by 1. So, if you come across an offset of 3, you would move three instructions forward, but change it to a 4 for the next time it is encountered.
此外,每當跳躍一次后,原來的偏移量會加一。所以,如果你從偏移量3起跳,你會向前跳三個然后原來的那個偏移量變成4。
For example, consider the following list of jump offsets:
比如說,看下這段跳躍偏移量列表:
0
3
0
1
-3
Positive jumps ("forward") move downward; negative jumps move upward. For legibility in this example, these offset values will be written all on one line, with the current instruction marked in parentheses. The following steps would be taken before an exit is found:
正值的偏移量會向前移動,負值的偏移量會向后移動。 為了更加方便閱讀,這些跳躍偏移量會被寫到一行里。當前指針讀取的偏移量會用括號標注。
before we have taken any steps.
在進行任何移動前
(0) 3 0 1 -3
jump with offset 0 (that is, don't jump at all). Fortunately, the instruction is then incremented to 1.
以偏移量0來做跳躍(并沒有移動)。幸運的是, 這個偏移量會在之后加一。
(1) 3 0 1 -3
step forward because of the instruction we just modified. The first instruction is incremented again, now to 2.
因為偏移量變化了,所以指針應該向前跳1,。 然后原先的偏移量加一,現在是2。
2 (3) 0 1 -3
jump all the way to the end; leave a 4 behind.
跳到列表末尾,原偏移量變成4。
2 4 0 1 (-3)
go back to where we just were; increment -3 to -2.
返回原來的位置,末尾的偏移量從-3變成-2。
2 (4) 0 1 -2
jump 4 steps forward, escaping the maze.
跳向前跳四步,跳出列表
2 5 0 1 -2
In this example, the exit is reached in 5 steps.
在這個例子里,從
How many steps does it take to reach the exit?
要走多少步才跳出列表?
解題思路
這一題比較簡單,只要讀取完所有的數值之后,將數值放入數組中。然后按照題目里說的一個個值操作就好了。