day02: Day 02: Corruption Checksum

Description Usage Arguments Details Examples

Description

Corruption Checksum

Usage

1
2
3
4
5
spreadsheet_checksum(spreadsheet, f_filter, f_combine)

evenly_divisible_pair(x)

max_min_pair(x)

Arguments

spreadsheet

a single string with a spreadsheet

f_filter

a function to find a pair on each spreadsheet row

f_combine

a function to apply on the pair from each line

x

a vector of integers to filter

Details

Part One

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.

For example, given the following spreadsheet:

1
2
3
5 1 9 5
7 5 3
2 4 6 8

In this example, the spreadsheet's checksum would be 8 + 4 + 6 = 18.

What is the checksum for the spreadsheet in your puzzle input?

Part Two

"Great work; looks like we're on the right track after all. Here's a star for your effort." However, the program seems a little worried. Can programs be worried?

"Based on what we're seeing, it looks like all the User wanted is some information about the evenly divisible values in the spreadsheet. Unfortunately, none of us are equipped for that kind of calculation - most of us specialize in bitwise operations."

It sounds like the goal is to find the only two numbers in each row where one evenly divides the other - that is, where the result of the division operation is a whole number. They would like you to find those numbers on each line, divide them, and add up each line's result.

For example, given the following spreadsheet:

1
2
3
5 9 2 8
9 4 7 3
3 8 6 5

In this example, the sum of the results would be 4 + 3 + 2 = 9.

What is the sum of each row's result in your puzzle input?

Examples

1
2
3
4
5
s1 <- "5 1 9 5\n7 5 3\n2 4 6 8"
spreadsheet_checksum(s1, max_min_pair, function(x) max(x) - min(x))

s2 <- "5 9 2 8\n9 4 7 3\n3 8 6 5"
spreadsheet_checksum(s2, evenly_divisible_pair, function(x) max(x) / min(x))

tjmahr/adventofcode17 documentation built on May 30, 2019, 2:29 p.m.