import std; void main() { File("input", "r").byLine.map!(to!int).array.multiply2EntriesThatSumTo(2020).writeln; } int multiply2EntriesThatSumTo(int[] input, int sum) { foreach (key1; input) { foreach (key2; input) { if (key2 == key1) { continue; } if (key1 + key2 == sum) { return key1 * key2; } } } return 0; } unittest { auto input = [1721, 979, 366, 299, 675, 1456]; assert(input.multiply2EntriesThatSumTo(2020) == 514579); }