01020304050607080910111213141516171819202122232425

Advent of Code

2017/1

Inverse Captcha

in C#

by encse

The night before Christmas, one of Santa's Elves calls you in a panic. "The printer's broken! We can't print the Naughty or Nice List!" By the time you make it to sub-basement 17, there are only a few minutes until midnight. "We have a big problem," she says; "there must be almost fifty bugs in this system, but nothing else can print The List. Stand in this square, quick! There's no time to explain; if you can convince them to pay you in stars, you'll be able to--" She pulls a lever and the world goes blurry.

When your eyes can focus again, everything seems a lot more pixelated than before. She must have sent you inside the computer! You check the system clock: 25 milliseconds until midnight. With that much time, you should be able to collect all fifty stars by December 25th.

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

using System.Linq;

namespace AdventOfCode.Y2017.Day01;

[ProblemName("Inverse Captcha")]
class Solution : Solver {

    public object PartOne(string input) => InverseCaptcha(input, 1);

    public object PartTwo(string input) => InverseCaptcha(input, input.Length / 2);

    int InverseCaptcha(string input, int skip) {
        return (
            from i in Enumerable.Range(0, input.Length)
            where input[i] == input[(i + skip) % input.Length]
            select int.Parse(input[i].ToString())
        ).Sum();
    }
}

Please ☆ my repo if you like it!

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