day03: Day 03: No Matter How You Slice It

Description Usage Arguments Details Value Examples

Description

No Matter How You Slice It

Usage

1
2
3

Arguments

x

a character vector of fabric claims

Details

Part One

The Elves managed to locate the chimney-squeeze prototype fabric for Santa's suit (thanks to [someone]title="WAS IT YOU" who helpfully wrote its box IDs on the wall of the warehouse in the middle of the night). Unfortunately, anomalies are still affecting them - nobody can even agree on how to cut the fabric.

The whole piece of fabric they're working on is a very large square - at least 1000 inches on each side.

Each Elf has made a claim about which area of fabric would be ideal for Santa's suit. All claims have an ID and consist of a single rectangle with edges parallel to the edges of the fabric. Each claim's rectangle is defined as follows:

A claim like #123 @ 3,2: 5x4 means that claim ID 123 specifies a rectangle 3 inches from the left edge, 2 inches from the top edge, 5 inches wide, and 4 inches tall. Visually, it claims the square inches of fabric represented by # (and ignores the square inches of fabric represented by .) in the diagram below:

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

The problem is that many of the claims overlap, causing two or more claims to cover part of the same areas. For example, consider the following claims:

1
2
3
#1 @ 1,3: 4x4
#2 @ 3,1: 4x4
#3 @ 5,5: 2x2

Visually, these claim the following areas:

1
2
3
4
5
6
7
8
........
...2222.
...2222.
.11XX22.
.11XX22.
.111133.
.111133.
........

The four square inches marked with X are claimed by both 1 and 2. (Claim 3, while adjacent to the others, does not overlap either of them.)

If the Elves all proceed with their own plans, none of them will have enough fabric. How many square inches of fabric are within two or more claims?

Part Two

Amidst the chaos, you notice that exactly one claim doesn't overlap by even a single square inch of fabric with any other claim. If you can somehow draw attention to it, maybe the Elves will be able to make Santa's suit after all!

For example, in the claims above, only claim 3 is intact after all claims are made.

What is the ID of the only claim that doesn't overlap?

Value

For Part One, count_overlapping_fabric_claims(x) returns the total number of squares that are claimed by more than one fabric claim. For Part Two, find_unique_fabric_claim(x) returns the ID of the claim that does not overlap any others.

Examples

1
2
3
4
5
6
x <- c(
  "#1 @ 1,3: 4x4",
  "#2 @ 3,1: 4x4",
  "#3 @ 5,5: 2x2")
count_overlapping_fabric_claims(x)
find_unique_fabric_claim(x)

tjmahr/adventofcode18 documentation built on May 24, 2019, 4:10 p.m.