--- Day 21: Scrambled Letters and Hash ---
The computer system you're breaking into uses a weird scrambling function to store its passwords. It shouldn't be much trouble to create your own scrambled password so you can add it to the system; you just have to implement the scrambler.
The scrambling function is a series of operations (the exact list is provided in your puzzle input). Starting with the password to be scrambled, apply each operation in succession to the string. The individual operations behave as follows:
swap position X with position Ymeans that the letters at indexesXandY(counting from0) should be swapped.swap letter X with letter Ymeans that the lettersXandYshould be swapped (regardless of where they appear in the string).rotate left/right X stepsmeans that the whole string should be rotated; for example, one right rotation would turnabcdintodabc.rotate based on position of letter Xmeans that the whole string should be rotated to the right based on the index of letterX(counting from0) as determined before this instruction does any rotations. Once the index is determined, rotate the string to the right one time, plus a number of times equal to that index, plus one additional time if the index was at least4.reverse positions X through Ymeans that the span of letters at indexesXthroughY(including the letters atXandY) should be reversed in order.move position X to position Ymeans that the letter which is at indexXshould be removed from the string, then inserted such that it ends up at indexY.
For example, suppose you start with abcde and perform the following operations:
swap position 4 with position 0swaps the first and last letters, producing the input for the next step,ebcda.swap letter d with letter bswaps the positions ofdandb:edcba.reverse positions 0 through 4causes the entire string to be reversed, producingabcde.rotate left 1 stepshifts all letters left one position, causing the first letter to wrap to the end of the string:bcdea.move position 1 to position 4removes the letter at position1(c), then inserts it at position4(the end of the string):bdeac.move position 3 to position 0removes the letter at position3(a), then inserts it at position0(the front of the string):abdec.rotate based on position of letter bfinds the index of letterb(1), then rotates the string right once plus a number of times equal to that index (2):ecabd.rotate based on position of letter dfinds the index of letterd(4), then rotates the string right once, plus a number of times equal to that index, plus an additional time because the index was at least4, for a total of6right rotations:decab.
After these steps, the resulting scrambled password is decab.
Now, you just need to generate a new scrambled password and you can access the system. Given the list of scrambling operations in your puzzle input, what is the result of scrambling abcdefgh?