summary refs log tree commit diff homepage
path: root/2016/src/bin/day19.rs
blob: 9afbf398629c0f7c605d6c6a7285f117509c1f44 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
use std::collections::VecDeque;
use std::io::{self, Read};

#[derive(Clone, Copy)]
struct Elf {
    position: usize,
    gifts: usize,
}

fn solve(count: usize) -> usize {
    let mut circle: VecDeque<Elf> = (0..count)
        .map(|i| Elf { position: i + 1, gifts: 1 })
        .collect();

    while circle.len() > 1 {
        let mut current = circle.pop_front().unwrap();
        let next = circle.pop_front().unwrap();
        current.gifts += next.gifts;
        circle.push_back(current);
    }

    circle.pop_front().unwrap().position
}

fn main() {
    let mut input = String::new();
    io::stdin().read_to_string(&mut input).unwrap();

    println!("Part 1: {}", solve(input.trim().parse().unwrap()));
}

#[test]
fn part1() {
    assert_eq!(3, solve(5));
}
r class='logheader'>2026-04-23Add dais from Left Hand of DarknessJune McEnroe I have not read it. This was contributed by the woman who made me install Real War: Not Fake. 2026-04-23Add y-d templateJune McEnroe 2026-03-23Replace tmppath pledge with rpath wpath cpathJune McEnroe 2026-03-23Add -ll for hilexJune McEnroe huh. should have always been there I guess, but now it actually matters, at least on OpenBSD? 2026-02-17Remove photo metadata directoriesJune McEnroe 2026-02-17Ignore photo metadataJune McEnroe I just don't want to be adding all this stuff to git. 2026-02-16Populate films datalist with 20 most recently usedJune McEnroe 2026-02-16Select last used bodyJune McEnroe 2026-02-15Don't break on trip with removed bodyJune McEnroe 2026-02-11Keep manpath.conf sortedJune McEnroe