01020304050607080910111213141516171819202122232425

Advent of Code

2016/6

Signals and Noise

in C#

by encse

Something is jamming your communications with Santa. Fortunately, your signal is only partially jammed, and protocol in situations like this is to switch to a simple repetition code to get the message through.

In this model, the same message is sent repeatedly. You've recorded the repeating message signal (your puzzle input), but the data seems quite corrupted - almost too badly to recover. Almost.

Read the full puzzle.

using System.Linq;

namespace AdventOfCode.Y2016.Day06;

[ProblemName("Signals and Noise")]
class Solution : Solver {

    public object PartOne(string input) => Decode(input).mostFrequent;
    public object PartTwo(string input) => Decode(input).leastFrequent;

    (string mostFrequent, string leastFrequent) Decode(string input) {
        var lines = input.Split('\n');
        string mostFrequent = "";
        string leastFrequent = "";
        for (int i = 0; i < lines[0].Length; i++) {
            var items = (from line in lines group line by line[i] into g orderby g.Count() select g.Key);
            mostFrequent += items.Last();
            leastFrequent += items.First();
        }
        return (mostFrequent: mostFrequent, leastFrequent: leastFrequent);
    }
}

Please ☆ my repo if you like it!

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