about summary refs log tree commit diff
diff options
context:
space:
mode:
authorLeah Neukirchen <leah@vuxu.org>2018-12-11 14:29:54 +0100
committerLeah Neukirchen <leah@vuxu.org>2018-12-11 14:29:54 +0100
commit4e3a081d08a79355219f8fcf78a9ae762d662b56 (patch)
tree6043ec8e7fce1ca911df91abe6177103a415902e
parenta0f397e739c8811fe4ab321f0ff7927c25bd6113 (diff)
downloadadventofcode2018-4e3a081d08a79355219f8fcf78a9ae762d662b56.tar.gz
adventofcode2018-4e3a081d08a79355219f8fcf78a9ae762d662b56.tar.xz
adventofcode2018-4e3a081d08a79355219f8fcf78a9ae762d662b56.zip
day09
-rw-r--r--day091
-rw-r--r--day09.rs33
2 files changed, 34 insertions, 0 deletions
diff --git a/day09 b/day09
new file mode 100644
index 0000000..fc88b57
--- /dev/null
+++ b/day09
@@ -0,0 +1 @@
+466 players; last marble is worth 71436 points
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());
+}