aboutsummaryrefslogtreecommitdiff
path: root/day09.rs
diff options
context:
space:
mode:
Diffstat (limited to 'day09.rs')
-rw-r--r--day09.rs33
1 files changed, 33 insertions, 0 deletions
diff --git a/day09.rs b/day09.rs
new file mode 100644
index 0000000..fe3fdc8
--- /dev/null
+++ b/day09.rs
@@ -0,0 +1,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());
+}