Added fifth day

This commit is contained in:
Alexander Munch-Hansen 2017-12-06 02:39:23 +01:00
parent ddfd12346e
commit 4e28fae0f5

View File

@ -33,3 +33,12 @@ Given a list of words, one had to figure out if the given list is a valid `passp
This first part was simply solved by converting each list to a set by calling `uniq` on it and then checking if the length is the same as for the original list. If not, there must have been some duplicates.
For the second part, if any word was a permutation of another word, this list was now not a valid passphrase. Because of this, it could be solved by looping through all words, taking the permutation and then checking if either of the permutation was already known and if so, the list was decided to be not a valid passphrase.
## The 5th of December
The input is a list of the offsets for each jump to where one has to go in an array. 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. Also, each jump incremented the previous offset by one.
Because of the 'outside the list' requirement, one could simply loop on `while input[i] != nil` in Ruby, since Ruby doesn't throw an `IndexOutOfBounds`-exception. Therefore, for the first part, one simply had to loop on the beforementioned while and for each iteration, then calculate the new offset and increment a counter to check how many times it has taken, since the goal was to tell when we went out of bounds.
For the second part, the only difference was that whenever the offset jumped from was 3 or higher, the offset was instead decremented by one.