Introduction
We start with Day 1 for which the actual problem is usually about transforming input data quickly, using the available library functions.
Solution
After reading input data line by line, we can easily get the input like
|
|
while what is needed to calculate actual answer is data in format like
|
|
To achieve that, we can make use of the created utility function, which treats such a list of lists as a matrix and does the transpose operation on it. This operation is about changing the indices of columns with the indices of rows, by simply remapping the data to new structure.
|
|
Having data in such formats, we can easily provide answers for both parts of Day 1.
Part One sums the absolute distances between pairs of numbers from each of the lists with the standard library utility functions
|
|
while Part Two is about counting the occurrences of each number in the second list and then making use of it to calculate
the expected score with simple call to sumOf { ... }
.
In the same time we can make use here of the DefaultMap<K, V>
defined in our utilities’ file.
Thanks to that approach, we can get the 0
count for each number that doesn’t occur in the second list and get the answer with simple
|
|