AOC 2022 — Day 4

Matt E.
4 min readJan 19, 2023

In this article I’ll present my solution for the fourth day of the Advent of Code 2022.

You can find here my solutions for the previous challenges : Day 1, Day 2, Day 3

https://adventofcode.com/2022/day/4

In order to unload the last supplies from the ship, the elves need to clear some space. To do this, each elf has been assigned a section to clean.

Elves notice that there’s some overlap between their assignments. In order to reduce duplication of work, they pair up and start listing their assignment (Your input).

The input has the following format :

2-4,6-8
2-3,4-5
5-7,7-9
2-8,3-7
6-6,4-6
2-6,4-8

Each line represents a pair of elves, with their assignments.

For example the first line is a pair where :

  • Elf 1 needs to clean sections 2, 3 and 4
  • Elf 2 needs to clean sections 6, 7 and 8

So there’s no overlap

But if we look at group 4 :

  • Elf 1 needs to clean sections 2, 3, 4, 5, 6, 7, 8
  • Elf 2 needs to clean sections 3, 4, 5, 6, 7

We have an overlap (3, 4, 5, 6 and 7 are in both assignments)

Part 1

--

--

Matt E.

Software engineer at Achiev & Jounco. Passionate about programming and entrepreneurship