01020304050607080910111213141516171819202122232425

Advent of Code

2017/2

Corruption Checksum

in C#

by encse

As you walk through the door, a glowing humanoid shape yells in your direction. "You there! Your state appears to be idle. Come help us repair the corruption in this spreadsheet - if we take another millisecond, we'll have to display an hourglass cursor!"

The spreadsheet consists of rows of apparently-random numbers. To make sure the recovery process is on the right track, they need you to calculate the spreadsheet's checksum. For each row, determine the difference between the largest value and the smallest value; the checksum is the sum of all of these differences.

Read the full puzzle.

using System.Linq;

namespace AdventOfCode.Y2017.Day02;

[ProblemName("Corruption Checksum")]
class Solution : Solver {

    public object PartOne(string input) {
        return (
            from line in input.Split('\n')
            let numbers = line.Split('\t').Select(int.Parse)
            select numbers.Max() - numbers.Min()
        ).Sum();
    }

    public object PartTwo(string input) {
        return (
            from line in input.Split('\n')
            let numbers = line.Split('\t').Select(int.Parse)
            from a in numbers
            from b in numbers
            where a > b && a % b == 0
            select a / b
        ).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