# Advent of Code – Day 5 Solution

This year, I’m posting my solutions to the puzzles in the Advent of Code. Each post will consist of pseudocode, with a link to the actual code I used to solve the puzzle on Github.

And now, on with the solution:

### Day 5, part 1

Simplified problem: Determine an 8-character code by calculating the MD5 sum of the puzzle input followed by an index starting at 0. The code is determined by the 6th digit in the first MD5 sum that starts with 00000. If the sum does not start with 00000, increase the index by 1, and calculate the sum of that input.

#### Solution

2. Set index=0
4. While password length < 8
1. Set md5sum =  MD5 sum of the string input + index (e.g. abc0)
2. Set md5sum =  MD5 sum of the string input + index (e.g. abc1)
3. End While
5. End While

md5sum is calculated using the following function:

### Day 5, part 2

Use the same input and index pattern to determine the password. This time, however, the MD5 hash must start with 00000, and you must use the 6th and 7th characters to determine the password.

The 6th character determines the location in the password (position 0-7). the 7th character is the password character itself. For instance MD5 hash 000006B472146F38A8D1C5B39E620EDC sets the 7th character in the password to B. The hash 000008EBAB696528EBCD9C5CA89C8243 is invalid, because 8 is not a valid position in the password. In this case, we continue calculating MD5 sums, ignoring this result.