summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--15/Cargo.toml11
-rw-r--r--15/src/main.rs52
-rw-r--r--15/tests/main.rs14
-rw-r--r--Cargo.lock8
-rw-r--r--Cargo.nix35
-rw-r--r--Cargo.toml1
6 files changed, 121 insertions, 0 deletions
diff --git a/15/Cargo.toml b/15/Cargo.toml
new file mode 100644
index 0000000..dcc368c
--- /dev/null
+++ b/15/Cargo.toml
@@ -0,0 +1,11 @@
+[package]
+name = "advent_15"
+version = "0.1.0"
+authors = ["Irene Knapp <ireneista@gmail.com>"]
+edition = "2018"
+
+[dependencies]
+advent_lib = { path = "../lib" }
+
+[dev-dependencies]
+assert_cmd = "0.10"
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(())
+}
+
diff --git a/15/tests/main.rs b/15/tests/main.rs
new file mode 100644
index 0000000..51cb39b
--- /dev/null
+++ b/15/tests/main.rs
@@ -0,0 +1,14 @@
+use assert_cmd::prelude::*;
+use std::process::Command;
+
+
+#[test]
+fn personal_input() -> Result<(), Box<dyn std::error::Error>> {
+  let mut command = Command::cargo_bin("advent_15")?;
+
+  command.arg("input");
+  command.assert().success().stdout("1280\n651639\n");
+
+  Ok(())
+}
+
diff --git a/Cargo.lock b/Cargo.lock
index 884e905..a63ce03 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -115,6 +115,14 @@ dependencies = [
 ]
 
 [[package]]
+name = "advent_15"
+version = "0.1.0"
+dependencies = [
+ "advent_lib",
+ "assert_cmd",
+]
+
+[[package]]
 name = "advent_lib"
 version = "0.1.0"
 
diff --git a/Cargo.nix b/Cargo.nix
index 70268e4..8ee5464 100644
--- a/Cargo.nix
+++ b/Cargo.nix
@@ -168,6 +168,16 @@ rec {
       # File a bug if you depend on any for non-debug work!
       debug = internal.debugCrate { inherit packageId; };
     };
+    "advent_15" = rec {
+      packageId = "advent_15";
+      build = internal.buildRustCrateWithFeatures {
+        packageId = "advent_15";
+      };
+
+      # Debug support which might change between releases.
+      # File a bug if you depend on any for non-debug work!
+      debug = internal.debugCrate { inherit packageId; };
+    };
     "advent_lib" = rec {
       packageId = "advent_lib";
       build = internal.buildRustCrateWithFeatures {
@@ -558,6 +568,31 @@ rec {
         ];
         
       };
+      "advent_15" = rec {
+        crateName = "advent_15";
+        version = "0.1.0";
+        edition = "2018";
+        crateBin = [
+          { name = "advent_15"; path = "src/main.rs"; }
+        ];
+        src = (builtins.filterSource sourceFilter ./15);
+        authors = [
+          "Irene Knapp <ireneista@gmail.com>"
+        ];
+        dependencies = [
+          {
+            name = "advent_lib";
+            packageId = "advent_lib";
+          }
+        ];
+        devDependencies = [
+          {
+            name = "assert_cmd";
+            packageId = "assert_cmd";
+          }
+        ];
+        
+      };
       "advent_lib" = rec {
         crateName = "advent_lib";
         version = "0.1.0";
diff --git a/Cargo.toml b/Cargo.toml
index 1bdc5f3..d8cc993 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -15,4 +15,5 @@ members = [
   "12",
   "13",
   "14",
+  "15",
 ]