
We’ll later use this function to check whether a given number is valid by passing this number and the list of the previous 25 numbers as arguments.įor convenience, we can define the function as an extension on a List of Long numbers. Let’s solve the task in Kotlin! For a start, let’s implement a function that checks whether a given list contains a pair of numbers that sum up to a given number.

Two numbers that sum to a valid number must be different from each other. We’ll call the number valid if it can be presented as a sum of two numbers from the previous sublist, and invalid otherwise. We need to attack a weakness in data encrypted with the eXchange-Masking Addition System (XMAS)! The data is a list of numbers, and we need to find the first number in the list (starting from the 26th) that is not the sum of any 2 of the 25 numbers before it.

While solving it, we’ll look into different ways to manipulate lists in Kotlin.

This post continues our “Idiomatic Kotlin” series and provides the solution for the Advent of Code Day 9* challenge.
