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