01020304050607080910111213141516171819202122232425

Advent of Code

2018/1

Chronal Calibration

in C#

by encse

"We've detected some temporal anomalies," one of Santa's Elves at the Temporal Anomaly Research and Detection Instrument Station tells you. She sounded pretty worried when she called you down here. "At 500-year intervals into the past, someone has been changing Santa's history!"

"The good news is that the changes won't propagate to our time stream for another 25 days, and we have a device" - she attaches something to your wrist - "that will let you fix the changes with no such propagation delay. It's configured to send you 500 years further into the past every few days; that was the best we could do on such short notice."

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

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

namespace AdventOfCode.Y2018.Day01;

[ProblemName("Chronal Calibration")]
class Solution : Solver {

    public object PartOne(string input) {
        return Frequencies(input).ElementAt(input.Split("\n").Count() - 1);
    }

    public object PartTwo(string input) {
        var seen = new HashSet<int>();
        foreach (var f in Frequencies(input)) {
            if (seen.Contains(f)) {
                return f;
            }
            seen.Add(f);
        }
        throw new Exception();
    }

    IEnumerable<int> Frequencies(string input) {
        var f = 0;
        while (true) {
            foreach (var d in input.Split("\n").Select(int.Parse)) {
                f += d;
                yield return f;
            }
        }
    }
}

Please ☆ my repo if you like it!

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