So this time around we’re working with strings.
The first part asks to build a simple checksum type algorithm to ensure the box ids are correct. I ended up solving it with basically just LINQ in C#.
Select returns the number of each character for each id. The second
Select returns whether those counts contain 2 and 3, meaning the id contains a character twice or contains a character thrice. The last part just multiplies the number of ids containing a multiple of 2 by the number of ids containing a multiple of 3.
The second part asks us to find the two matching boxes by finding the two ids that differ by only 1 character. Here I went with a simple brute force of checking all the pairs and returning the first one that matches the criteria.
I opted again for LINQ to calculate the matching characters. If the two characters match, I return it, otherwise I replace it with a space character which I then remove. The first pair which has 1 less common letters than the number of letters in the id is the one we want. I was afraid running a
O(n²) algorithm would require too much compute time, but the input was small enough that I didn’t need any optimization.