diff options
author | kaiwu <kaiwu2004@gmail.com> | 2022-03-19 20:09:20 +0800 |
---|---|---|
committer | kaiwu <kaiwu2004@gmail.com> | 2022-03-19 20:09:20 +0800 |
commit | fa2a00daea1f4267488d7b989faf88fe3a10410d (patch) | |
tree | 07e9d36ebf441b7e36a825adb97751ba7087ffa9 | |
parent | 9a5732aeb6d0966c70c73be76802eb039c65ea18 (diff) | |
download | advent-of-code-fa2a00daea1f4267488d7b989faf88fe3a10410d.tar.gz advent-of-code-fa2a00daea1f4267488d7b989faf88fe3a10410d.zip |
day13
-rw-r--r-- | src/2015/day13/README.md | 37 | ||||
-rw-r--r-- | src/2015/day13/aoc.cpp | 5 | ||||
-rw-r--r-- | src/2015/day13/aoc.h | 7 | ||||
-rw-r--r-- | src/2015/day13/input | 56 | ||||
-rw-r--r-- | src/CMakeLists.txt | 1 | ||||
-rw-r--r-- | test/test_2015.cpp | 1 |
6 files changed, 107 insertions, 0 deletions
diff --git a/src/2015/day13/README.md b/src/2015/day13/README.md new file mode 100644 index 0000000..94262d6 --- /dev/null +++ b/src/2015/day13/README.md @@ -0,0 +1,37 @@ +--- Day 13: Knights of the Dinner Table --- + +In years past, the holiday feast with your family hasn't gone so well. Not everyone gets along! This year, you resolve, will be different. You're going to find the optimal seating arrangement and avoid all those awkward conversations. + +You start by writing up a list of everyone invited and the amount their happiness would increase or decrease if they were to find themselves sitting next to each other person. You have a circular table that will be just big enough to fit everyone comfortably, and so each person will have exactly two neighbors. + +For example, suppose you have only four attendees planned, and you calculate their potential happiness as follows: + +Alice would gain 54 happiness units by sitting next to Bob. +Alice would lose 79 happiness units by sitting next to Carol. +Alice would lose 2 happiness units by sitting next to David. +Bob would gain 83 happiness units by sitting next to Alice. +Bob would lose 7 happiness units by sitting next to Carol. +Bob would lose 63 happiness units by sitting next to David. +Carol would lose 62 happiness units by sitting next to Alice. +Carol would gain 60 happiness units by sitting next to Bob. +Carol would gain 55 happiness units by sitting next to David. +David would gain 46 happiness units by sitting next to Alice. +David would lose 7 happiness units by sitting next to Bob. +David would gain 41 happiness units by sitting next to Carol. + +Then, if you seat Alice next to David, Alice would lose 2 happiness units (because David talks so much), but David would gain 46 happiness units (because Alice is such a good listener), for a total change of 44. + +If you continue around the table, you could then seat Bob next to Alice (Bob gains 83, Alice gains 54). Finally, seat Carol, who sits next to Bob (Carol gains 60, Bob loses 7) and David (Carol gains 55, David gains 41). The arrangement looks like this: + + +41 +46 ++55 David -2 +Carol Alice ++60 Bob +54 + -7 +83 + +After trying every other seating arrangement in this hypothetical scenario, you find that this one is the most optimal, with a total change in happiness of 330. + +What is the total change in happiness for the optimal seating arrangement of the actual guest list? + + + diff --git a/src/2015/day13/aoc.cpp b/src/2015/day13/aoc.cpp new file mode 100644 index 0000000..1c33c66 --- /dev/null +++ b/src/2015/day13/aoc.cpp @@ -0,0 +1,5 @@ +#include "aoc.h" + +namespace aoc2015 { + +} diff --git a/src/2015/day13/aoc.h b/src/2015/day13/aoc.h new file mode 100644 index 0000000..7eb843c --- /dev/null +++ b/src/2015/day13/aoc.h @@ -0,0 +1,7 @@ +#pragma once + +#include "common.h" + +namespace aoc2015 { + +} diff --git a/src/2015/day13/input b/src/2015/day13/input new file mode 100644 index 0000000..35be357 --- /dev/null +++ b/src/2015/day13/input @@ -0,0 +1,56 @@ +Alice would gain 54 happiness units by sitting next to Bob. +Alice would lose 81 happiness units by sitting next to Carol. +Alice would lose 42 happiness units by sitting next to David. +Alice would gain 89 happiness units by sitting next to Eric. +Alice would lose 89 happiness units by sitting next to Frank. +Alice would gain 97 happiness units by sitting next to George. +Alice would lose 94 happiness units by sitting next to Mallory. +Bob would gain 3 happiness units by sitting next to Alice. +Bob would lose 70 happiness units by sitting next to Carol. +Bob would lose 31 happiness units by sitting next to David. +Bob would gain 72 happiness units by sitting next to Eric. +Bob would lose 25 happiness units by sitting next to Frank. +Bob would lose 95 happiness units by sitting next to George. +Bob would gain 11 happiness units by sitting next to Mallory. +Carol would lose 83 happiness units by sitting next to Alice. +Carol would gain 8 happiness units by sitting next to Bob. +Carol would gain 35 happiness units by sitting next to David. +Carol would gain 10 happiness units by sitting next to Eric. +Carol would gain 61 happiness units by sitting next to Frank. +Carol would gain 10 happiness units by sitting next to George. +Carol would gain 29 happiness units by sitting next to Mallory. +David would gain 67 happiness units by sitting next to Alice. +David would gain 25 happiness units by sitting next to Bob. +David would gain 48 happiness units by sitting next to Carol. +David would lose 65 happiness units by sitting next to Eric. +David would gain 8 happiness units by sitting next to Frank. +David would gain 84 happiness units by sitting next to George. +David would gain 9 happiness units by sitting next to Mallory. +Eric would lose 51 happiness units by sitting next to Alice. +Eric would lose 39 happiness units by sitting next to Bob. +Eric would gain 84 happiness units by sitting next to Carol. +Eric would lose 98 happiness units by sitting next to David. +Eric would lose 20 happiness units by sitting next to Frank. +Eric would lose 6 happiness units by sitting next to George. +Eric would gain 60 happiness units by sitting next to Mallory. +Frank would gain 51 happiness units by sitting next to Alice. +Frank would gain 79 happiness units by sitting next to Bob. +Frank would gain 88 happiness units by sitting next to Carol. +Frank would gain 33 happiness units by sitting next to David. +Frank would gain 43 happiness units by sitting next to Eric. +Frank would gain 77 happiness units by sitting next to George. +Frank would lose 3 happiness units by sitting next to Mallory. +George would lose 14 happiness units by sitting next to Alice. +George would lose 12 happiness units by sitting next to Bob. +George would lose 52 happiness units by sitting next to Carol. +George would gain 14 happiness units by sitting next to David. +George would lose 62 happiness units by sitting next to Eric. +George would lose 18 happiness units by sitting next to Frank. +George would lose 17 happiness units by sitting next to Mallory. +Mallory would lose 36 happiness units by sitting next to Alice. +Mallory would gain 76 happiness units by sitting next to Bob. +Mallory would lose 34 happiness units by sitting next to Carol. +Mallory would gain 37 happiness units by sitting next to David. +Mallory would gain 40 happiness units by sitting next to Eric. +Mallory would gain 18 happiness units by sitting next to Frank. +Mallory would gain 7 happiness units by sitting next to George. diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index dd106de..d3c584d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -12,6 +12,7 @@ set(SOLUTION_FILES "2015/day10/aoc.cpp" "2015/day11/aoc.cpp" "2015/day12/aoc.cpp" + "2015/day13/aoc.cpp" ) add_library(solution SHARED ${SOLUTION_FILES}) diff --git a/test/test_2015.cpp b/test/test_2015.cpp index 4cc9a2a..626bbf3 100644 --- a/test/test_2015.cpp +++ b/test/test_2015.cpp @@ -10,6 +10,7 @@ #include "2015/day10/aoc.h" #include "2015/day11/aoc.h" #include "2015/day12/aoc.h" +#include "2015/day13/aoc.h" #include "catch.hpp" #include <stdio.h> |