01020304050607080910111213141516171819202122232425

Advent of Code

2020/1

Report Repair

in C#

by encse

After saving Christmas five years in a row, you've decided to take a vacation at a nice resort on a tropical island. Surely, Christmas will go on without you.

The tropical island has its own currency and is entirely cash-only. The gold coins used there have a little picture of a starfish; the locals just call them stars. None of the currency exchanges seem to have heard of them, but somehow, you'll need to find fifty of these coins by the time you arrive so you can pay the deposit on your room.

Visit the website for the full story and full puzzle description.

using System.Collections.Generic;
using System.Linq;

namespace AdventOfCode.Y2020.Day01;

[ProblemName("Report Repair")]
class Solution : Solver {

    public object PartOne(string input) {
        var numbers = Numbers(input);
        return (
            from x in numbers 
            let y = 2020 - x
            where numbers.Contains(y)
            select x * y
        ).First();
    }

    public object PartTwo(string input) {
        var numbers = Numbers(input);
        return (
            from x in numbers 
            from y in numbers 
            let z = 2020 - x - y
            where numbers.Contains(z)
            select x * y * z
        ).First();
    }

    HashSet<int> Numbers(string input) {
        return input.Split('\n').Select(int.Parse).ToHashSet<int>();
    }
}

Please ☆ my repo if you like it!

© 2025 Advent of Code is a registered trademark in the US Images provided by Bing image creator