aboutsummaryrefslogtreecommitdiff
path: root/day09.rs
blob: fe3fdc8e2e77ffdca4e942b63c2afe78fe679c79 (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
use std::collections::VecDeque;

const mp : usize = 466;
const mr : usize = 71436;

fn main() {
    let mut s = VecDeque::new();
    s.push_back(0);

    let mut scores = [0usize; mp + 1];

    for (n, p) in (1..mp+1).cycle().take(mr*100).enumerate() {
        let m = n + 1;
        if m % 23 == 0 {
            scores[p] += m;

            for _ in 0..7 {
                let x = s.pop_back().unwrap();
                s.push_front(x);
            }

            scores[p] += s.pop_back().unwrap();
            let x = s.pop_front().unwrap();
            s.push_back(x);
        } else {
            let x = s.pop_front().unwrap();
            s.push_back(x);
            s.push_back(m);
        }
    }

    println!("{}", scores.iter().max().unwrap());
}