Advent of Code Day 10 結哈希

解題語言不限Java

拖更了,不好意思

題目內容

You come across some programs that are trying to implement a software emulation of a hash based on knot-tying. The hash these programs are implementing isn't very strong, but you decide to help them anyway. You make a mental note to remind the Elves later not to invent their own cryptographic functions.
你走在路上,看到一些程序正在嘗試執行一個用結哈希來進行的軟件仿真。這些程序生成的哈希魯棒性并不高,但是你決定去幫助他們。你暗暗記下回去是告訴精靈他們的加密程序并不強。
This hash function simulates tying a knot in a circle of string with 256 marks on it. Based on the input to be hashed, the function repeatedly selects a span of string, brings the ends together, and gives the span a half-twist to reverse the order of the marks within it. After doing this many times, the order of the marks is used to build the resulting hash.
這個哈希程序模擬了一個有256個元素的環裝結構打結的過程。基于輸入,這個程序重復選擇一段字符串,并且將其反向。多次循環過后,環裝結構的元素會被用來建立哈希。

  4--5   pinch   4  5           4   1
 /    \  5,0,1  / \/ \  twist  / \ / \
3      0  -->  3      0  -->  3   X   0
 \    /         \ /\ /         \ / \ /
  2--1           2  1           2   5

To achieve this, begin with a list of numbers from 0 to 255, a current position which begins at 0 (the first element in the list), a skip size (which starts at 0), and a sequence of lengths (your puzzle input).
為了從一個從0到255的數組達到這種效果,需要一個當前位置(從零開始),一個跳躍大小(從零開始)和一組長度(謎題輸入)。
Then, for each length:
然后對于每一個長度:
Reverse the order of that length of elements in the list, starting with the element at the current position.
翻轉指定長度的數組的順序,從當前位置開始。
Move the current position forward by that length plus the skip size.
當前位置向前移動長度跳躍大小的和。
Increase the skip size by one.
跳躍大小加一。
The list is circular; if the current position and the length try to reverse elements beyond the end of the list, the operation reverses using as many extra elements as it needs from the front of the list. If the current position moves past the end of the list, it wraps around to the front. Lengths larger than the size of the list are invalid.
這個列表是循環的,如果當前位置大于數組長度(256),當前位置會被重置到0。
Here's an example using a smaller list:
這里是個小的例子:
Suppose we instead only had a circular list containing five elements, 0, 1, 2, 3, 4, and were given input lengths of 3, 4, 1, 5.
假設數組只有5個元素大0,1,2,3,4,并且輸入長度為3,4,1,5
The list begins as [0] 1 2 3 4 (where square brackets indicate the current position).
這個例子從[0] 1 2 3 4,(中括號指代當前位置在數組中的位置)。
The first length, 3, selects ([0] 1 2) 3 4 (where parentheses indicate the sublist to be reversed).
第一個長度是3,選擇([0] 1 2) 3 4(小括號代表要被翻轉的數組)
After reversing that section (0 1 2 into 2 1 0), we get ([2] 1 0) 3 4.
在第一次翻轉之后(0 1 22 1 0),我們可以得到([2] 1 0) 3 4
Then, the current position moves forward by the length, 3, plus the skip size, 0: 2 1 0 [3] 4. Finally, the skip size increases to 1.
在之后,當前位置向前移動三加上跳躍大小02 1 0 [3] 4。最后,跳躍大小加一。
The second length, 4, selects a section which wraps: 2 1) 0 ([3] 4.
第二個長度是4,選擇2 1) 0 ([3] 4
The sublist 3 4 2 1 is reversed to form 1 2 4 3: 4 3) 0 ([1] 2.
翻轉指定部分之后(3 4 2 11 2 4 3),我們可以得到4 3) 0 ([1] 2
The current position moves forward by the length plus the skip size, a total of 5, causing it not to move because it wraps around: 4 3 0 [1] 2. The skip size increases to 2.
在之后,當前位置向前移動五,到達數組結尾并返回:4 3 0 [1] 2。最后,跳躍大小加到二。
The third length, 1, selects a sublist of a single element, and so reversing it has no effect.
The current position moves forward by the length (1) plus the skip size (2): 4 [3] 0 1 2. The skip size increases to 3.
第三個長度是1,選擇一個元素,所以沒有效果。當前位置向前移動34 [3] 0 1 2,跳躍大小加到三。
The fourth length, 5, selects every element starting with the second: 4) ([3] 0 1 2. Reversing this sublist (3 0 1 2 4 into 4 2 1 0 3) produces: 3) ([4] 2 1 0.
第二個長度是5,選擇每一個在數組中的元素4) ([3] 0 1 2,翻轉它(3 0 1 2 44 2 1 0 3) 3) ([4] 2 1 0.
Finally, the current position moves forward by 8: 3 4 2 1 [0]. The skip size increases to 4.
最后當前位置移動8,跳躍大小變為4。
In this example, the first two numbers in the list end up being 3 and 4; to check the process, you can multiply them together to produce 12.
在例子里,數組前兩個的乘積為(3x4)12。

However, you should instead use the standard list size of 256 (with values 0 to 255) and the sequence of lengths in your puzzle input. Once this process is complete, what is the result of multiplying the first two numbers in the list?
但是,你的數組有256個位長,長度列表為你的謎題輸入。當序列完成之后,頭兩個元素的乘積是多少?

解題思路

鑒于我手上還有Day 11 和Day 12 的沒有搞完,大家就等等吧hhh

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。