Function aoc::y15d13::y15d13

source ·
pub fn y15d13(input: &str, me: bool) -> i32
Expand description

The solution for the day thirteen challenge.

We take the input as a string and a boolean specifying if we’re also attending dinner or not. Then much like on day nine we start by parsing the input to compute the happiness change of each guest sitting next to every other guest. If we’re attending dinner then we also add a Me entry with happiness change of 0. Then again like in day nine we compute all of the possible seating arrangements (permutations) and then calculate the happiness for each guest. Differently from day nine we use circular windows to account for the first and last guest in the list sitting next to each other. Like in day nine we add the total happiness to a std::collections::BinaryHeap to make getting the final, largest value easy.

§Example

// probably read this from the input file...
let input = concat!(
    "Bob would gain 10 happiness units by sitting next to Alice.\n",
    "Bob would gain 20 happiness units by sitting next to Jim.\n",
    "Bob would gain 30 happiness units by sitting next to Andy.\n",
    "Alice would lose 10 happiness units by sitting next to Bob.\n",
    "Alice would lose 20 happiness units by sitting next to Jim.\n",
    "Alice would lose 30 happiness units by sitting next to Andy.\n",
    "Jim would gain 10 happiness units by sitting next to Alice.\n",
    "Jim would gain 20 happiness units by sitting next to Bob.\n",
    "Jim would gain 30 happiness units by sitting next to Andy.\n",
    "Andy would lose 10 happiness units by sitting next to Alice.\n",
    "Andy would lose 20 happiness units by sitting next to Jim.\n",
    "Andy would lose 30 happiness units by sitting next to Bob.",
);
assert_eq!(y15d13(input, false), 10);
assert_eq!(y15d13(input, true), 50);