summary refs log tree commit diff
path: root/15/src
diff options
context:
space:
mode:
authorIrene Knapp <ireneista@gmail.com>2020-12-15 00:31:26 -0800
committerIrene Knapp <ireneista@gmail.com>2020-12-15 00:31:26 -0800
commit7357cbdbd4424a06db8fb11546626f97783135a6 (patch)
tree1877edb8a3321ab75a27a257484670c53f294d72 /15/src
parent30fb06f502d04d9a0b78cb21df36949dca6d5c02 (diff)
15
Diffstat (limited to '15/src')
-rw-r--r--15/src/main.rs52
1 files changed, 52 insertions, 0 deletions
diff --git a/15/src/main.rs b/15/src/main.rs
new file mode 100644
index 0000000..12bf0fa
--- /dev/null
+++ b/15/src/main.rs
@@ -0,0 +1,52 @@
+use advent_lib::prelude::*;
+
+use std::collections::BTreeMap;
+
+
+
+fn main() -> Result<()> {
+  let args = std::env::args();
+  if args.len() != 1 {
+    eprintln!("Usage: advent");
+  }
+
+  let starting_numbers = vec![2, 15, 0, 9, 1, 20];
+
+  let mut history: BTreeMap<usize, usize> = BTreeMap::new();
+  let mut output = 0;
+  let mut next_output = 0;
+
+  for i in 0 .. starting_numbers.len() {
+    output = starting_numbers[i];
+    next_output = match history.get(&output) {
+      Some(previous) => i - previous,
+      None => 0,
+    };
+    history.insert(output, i);
+  }
+
+  for i in starting_numbers.len() .. 2020 {
+    output = next_output;
+    next_output = match history.get(&output) {
+      Some(previous) => i - previous,
+      None => 0,
+    };
+    history.insert(output, i);
+  }
+
+  println!("{}", output);
+
+  for i in 2020 .. 30000000 {
+    output = next_output;
+    next_output = match history.get(&output) {
+      Some(previous) => i - previous,
+      None => 0,
+    };
+    history.insert(output, i);
+  }
+
+  println!("{}", output);
+
+  Ok(())
+}
+