summary refs log tree commit diff
path: root/02
diff options
context:
space:
mode:
authorIrene Knapp <ireneista@gmail.com>2021-12-01 21:20:09 -0800
committerIrene Knapp <ireneista@gmail.com>2021-12-01 21:20:09 -0800
commit7573a5ecb3efcc690182cfc9a3948e01df7b7442 (patch)
treebfd74f252683dfee60f0659204ef42be6421e8b5 /02
parentaed6777886ca340e392a039150a3465e6436e0f8 (diff)
02
Diffstat (limited to '02')
-rw-r--r--02/Cargo.toml11
-rw-r--r--02/input1000
-rw-r--r--02/src/main.rs70
-rw-r--r--02/tests/main.rs17
4 files changed, 1098 insertions, 0 deletions
diff --git a/02/Cargo.toml b/02/Cargo.toml
new file mode 100644
index 0000000..fea9c0e
--- /dev/null
+++ b/02/Cargo.toml
@@ -0,0 +1,11 @@
+[package]
+name = "advent_02"
+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/02/input b/02/input
new file mode 100644
index 0000000..aef25e3
--- /dev/null
+++ b/02/input
@@ -0,0 +1,1000 @@
+forward 8
+forward 3
+down 8
+forward 4
+down 2
+down 4
+down 8
+down 4
+down 7
+up 4
+down 6
+down 2
+forward 7
+down 5
+down 7
+down 5
+forward 8
+forward 4
+forward 3
+down 4
+forward 2
+up 3
+up 6
+forward 7
+down 4
+down 2
+forward 7
+up 3
+forward 8
+down 4
+down 6
+forward 3
+forward 9
+down 9
+down 6
+forward 8
+up 8
+forward 3
+down 8
+down 4
+forward 7
+forward 3
+up 9
+down 8
+forward 7
+forward 5
+forward 3
+down 1
+down 4
+forward 1
+down 6
+forward 9
+up 2
+forward 3
+down 2
+down 1
+up 5
+down 8
+down 7
+down 5
+down 9
+up 7
+forward 4
+down 9
+down 8
+down 4
+forward 3
+down 1
+up 8
+down 1
+down 8
+forward 4
+up 1
+forward 7
+down 6
+down 2
+forward 3
+down 9
+forward 9
+forward 4
+down 1
+up 6
+down 1
+up 2
+down 4
+down 9
+down 7
+forward 5
+down 3
+up 9
+forward 4
+up 5
+down 9
+forward 1
+forward 7
+forward 1
+down 8
+forward 5
+down 2
+down 4
+down 3
+forward 4
+down 9
+up 7
+up 1
+forward 4
+up 2
+forward 4
+forward 4
+down 1
+down 5
+forward 6
+forward 1
+down 6
+forward 8
+forward 8
+forward 6
+down 3
+forward 3
+forward 1
+forward 5
+forward 7
+down 5
+forward 8
+down 7
+down 8
+forward 7
+forward 8
+down 7
+forward 7
+up 2
+up 9
+down 1
+forward 1
+forward 6
+up 3
+up 6
+down 2
+down 4
+forward 2
+up 8
+forward 5
+up 9
+up 5
+down 2
+forward 5
+forward 9
+up 3
+forward 7
+down 4
+down 3
+down 2
+forward 9
+up 4
+down 7
+down 1
+forward 9
+forward 3
+up 4
+forward 1
+up 6
+forward 5
+forward 2
+forward 2
+down 9
+forward 1
+up 7
+forward 3
+down 1
+down 5
+up 8
+down 5
+forward 5
+forward 5
+down 9
+up 5
+forward 8
+up 9
+down 1
+forward 1
+down 7
+up 3
+down 9
+down 9
+down 5
+up 6
+forward 7
+down 5
+down 2
+down 5
+forward 3
+forward 2
+forward 9
+forward 5
+forward 6
+up 7
+up 7
+forward 4
+forward 2
+up 4
+up 6
+down 8
+up 9
+up 5
+down 8
+forward 4
+up 9
+forward 8
+forward 3
+down 6
+down 6
+down 7
+down 6
+forward 7
+up 5
+down 2
+down 5
+forward 2
+up 5
+forward 7
+down 5
+up 4
+up 2
+forward 2
+forward 9
+forward 5
+forward 8
+up 4
+forward 6
+up 7
+forward 5
+down 2
+down 3
+down 8
+up 2
+down 2
+up 1
+up 7
+down 1
+down 6
+down 9
+down 7
+forward 8
+up 8
+up 9
+down 9
+forward 6
+forward 6
+down 6
+forward 3
+forward 4
+forward 6
+forward 7
+down 5
+down 8
+forward 7
+forward 9
+down 4
+up 9
+forward 8
+down 6
+down 1
+down 2
+forward 4
+down 5
+up 1
+forward 1
+down 6
+forward 4
+forward 2
+forward 6
+down 8
+up 2
+up 8
+forward 3
+down 6
+forward 7
+down 1
+forward 1
+forward 8
+down 8
+down 8
+down 2
+forward 8
+down 4
+up 8
+down 6
+forward 2
+down 5
+up 3
+up 1
+down 2
+forward 4
+up 7
+forward 2
+up 9
+forward 1
+down 5
+forward 3
+up 9
+up 4
+down 4
+up 6
+down 1
+forward 9
+up 5
+forward 5
+up 4
+down 6
+forward 2
+up 6
+forward 5
+forward 5
+down 4
+up 7
+forward 2
+down 9
+down 8
+down 7
+forward 4
+forward 7
+down 4
+forward 9
+up 2
+forward 1
+up 4
+down 8
+forward 9
+up 2
+up 5
+down 7
+up 6
+forward 7
+up 1
+forward 3
+down 3
+down 2
+down 6
+down 6
+forward 3
+down 2
+down 2
+down 5
+down 4
+down 6
+down 2
+forward 7
+down 6
+forward 4
+down 5
+down 7
+down 3
+forward 2
+forward 8
+forward 1
+up 6
+down 8
+down 4
+up 5
+forward 5
+down 7
+forward 5
+forward 8
+forward 7
+down 8
+down 5
+down 3
+up 2
+forward 8
+forward 7
+down 6
+up 1
+down 9
+down 3
+down 7
+down 2
+forward 9
+forward 2
+forward 4
+forward 8
+forward 3
+forward 2
+down 3
+down 8
+up 7
+down 7
+down 1
+forward 8
+down 2
+up 4
+forward 9
+down 6
+forward 5
+forward 8
+forward 1
+forward 4
+down 6
+down 1
+down 6
+forward 1
+forward 7
+down 3
+down 3
+down 1
+up 2
+down 6
+down 5
+down 6
+forward 5
+forward 2
+forward 1
+forward 8
+up 5
+down 2
+down 9
+down 9
+down 5
+down 3
+up 6
+forward 2
+down 7
+down 7
+down 2
+down 2
+up 6
+forward 8
+forward 6
+forward 4
+down 1
+forward 7
+down 5
+up 9
+forward 5
+down 4
+down 9
+up 7
+forward 1
+up 3
+up 7
+forward 6
+forward 8
+up 6
+up 3
+forward 4
+up 3
+down 1
+forward 8
+forward 1
+up 3
+forward 7
+up 2
+forward 6
+forward 2
+down 2
+down 9
+down 9
+forward 1
+forward 8
+down 5
+forward 4
+forward 5
+forward 5
+down 9
+forward 8
+up 8
+down 6
+down 2
+down 5
+down 6
+up 9
+up 8
+down 4
+down 9
+up 4
+forward 6
+forward 1
+forward 3
+up 4
+up 3
+forward 3
+forward 8
+down 1
+down 2
+down 2
+forward 9
+forward 4
+up 2
+forward 7
+down 4
+up 1
+forward 2
+forward 9
+forward 8
+down 4
+down 7
+up 7
+down 1
+forward 3
+down 7
+down 8
+up 2
+forward 2
+forward 8
+forward 4
+forward 4
+down 5
+forward 8
+down 2
+up 7
+down 1
+up 9
+up 5
+down 3
+forward 6
+forward 2
+forward 6
+down 5
+down 6
+forward 9
+up 5
+up 6
+down 4
+down 5
+up 4
+down 6
+down 2
+down 5
+down 4
+forward 7
+forward 6
+down 8
+forward 2
+down 5
+down 7
+down 2
+forward 8
+forward 6
+down 3
+forward 4
+up 6
+down 9
+down 3
+forward 3
+forward 3
+down 9
+up 1
+up 3
+forward 3
+forward 6
+forward 1
+forward 4
+forward 3
+forward 3
+forward 3
+down 6
+down 8
+forward 3
+down 5
+forward 8
+forward 3
+down 4
+up 3
+up 1
+down 7
+forward 7
+up 6
+forward 7
+down 4
+down 7
+up 9
+down 9
+forward 8
+down 5
+down 2
+forward 9
+down 3
+forward 4
+forward 4
+forward 4
+forward 6
+down 1
+up 5
+forward 8
+down 6
+forward 5
+up 5
+up 5
+down 2
+down 9
+down 7
+up 3
+up 7
+up 6
+forward 2
+forward 6
+up 9
+forward 5
+forward 2
+up 4
+down 4
+down 5
+forward 7
+down 5
+down 7
+forward 3
+down 6
+down 1
+forward 6
+up 5
+up 6
+up 3
+down 9
+up 7
+forward 9
+down 3
+forward 4
+up 2
+forward 9
+down 2
+up 2
+up 5
+forward 1
+down 8
+down 1
+down 8
+up 2
+forward 9
+forward 1
+up 2
+down 1
+up 1
+forward 2
+down 7
+forward 9
+up 1
+forward 8
+down 5
+down 5
+down 9
+forward 5
+down 7
+down 1
+forward 9
+down 5
+forward 9
+forward 9
+down 6
+down 5
+down 6
+forward 3
+down 4
+up 8
+down 6
+up 4
+down 9
+up 1
+up 2
+up 8
+forward 6
+down 7
+down 4
+down 9
+down 3
+forward 9
+down 5
+forward 6
+down 6
+forward 7
+down 9
+forward 2
+forward 2
+down 8
+down 7
+forward 5
+down 8
+forward 6
+down 1
+forward 6
+forward 7
+forward 3
+forward 2
+forward 1
+forward 1
+down 9
+forward 7
+up 9
+down 5
+forward 6
+down 4
+down 2
+forward 4
+forward 3
+forward 9
+down 8
+down 2
+forward 4
+down 8
+down 6
+forward 9
+down 7
+forward 1
+up 1
+forward 3
+down 5
+down 8
+up 6
+forward 9
+forward 4
+down 2
+forward 4
+up 2
+forward 9
+down 5
+down 1
+down 9
+forward 5
+down 9
+forward 1
+down 9
+forward 8
+down 5
+forward 9
+forward 8
+up 8
+down 7
+up 9
+down 5
+up 9
+forward 7
+forward 7
+forward 1
+up 2
+up 2
+forward 6
+up 5
+up 5
+down 7
+forward 2
+up 8
+forward 8
+down 8
+forward 7
+forward 8
+down 7
+down 8
+forward 4
+forward 2
+down 8
+up 4
+down 1
+up 7
+forward 4
+forward 3
+down 6
+up 6
+forward 6
+down 1
+forward 3
+down 6
+forward 6
+up 3
+up 1
+up 5
+down 1
+up 9
+down 8
+forward 7
+forward 9
+up 2
+forward 2
+forward 6
+up 2
+up 3
+forward 1
+forward 2
+forward 8
+down 6
+forward 5
+down 8
+forward 2
+up 1
+down 1
+down 3
+forward 9
+down 6
+down 1
+down 6
+down 6
+down 6
+down 1
+up 6
+down 6
+forward 6
+down 5
+down 2
+up 5
+forward 7
+down 3
+forward 9
+forward 2
+down 2
+down 1
+down 9
+up 3
+down 2
+forward 2
+forward 6
+down 4
+up 7
+up 3
+up 9
+forward 3
+forward 8
+forward 9
+forward 4
+forward 2
+up 7
+up 5
+down 9
+forward 1
+up 1
+down 7
+forward 5
+forward 5
+down 3
+forward 1
+forward 6
+up 8
+down 4
+down 2
+up 2
+forward 2
+forward 1
+down 4
+up 9
+down 1
+down 4
+down 6
+forward 3
+forward 7
+down 4
+up 8
+down 6
+forward 7
+forward 4
+up 2
+down 8
+forward 5
+down 1
+forward 7
+down 1
+up 6
+down 9
+forward 3
+forward 1
+up 2
+up 4
+forward 8
+forward 1
+up 8
+forward 3
+forward 7
+up 9
+up 6
+up 9
+down 9
+down 5
+forward 8
+forward 7
+down 5
+forward 7
+forward 6
+forward 8
+up 4
+forward 6
+down 6
+up 8
+down 7
+up 8
+forward 6
+forward 7
+down 4
+forward 4
+up 2
+forward 9
+down 6
+down 2
+down 8
+forward 6
+up 2
+up 8
+forward 2
+down 3
+forward 7
+forward 6
+down 9
+up 1
+forward 1
+down 8
+down 8
+forward 4
+forward 4
+up 6
+down 8
+up 8
+forward 1
+forward 1
+down 6
+up 3
+up 7
+forward 1
+forward 1
+up 2
+forward 2
+down 4
+up 8
+forward 1
+up 7
+down 2
+forward 2
+down 1
+forward 1
+down 4
+forward 4
+forward 8
+up 5
+down 6
+up 8
+forward 4
+down 3
+up 6
+forward 3
+forward 4
+down 5
+forward 1
+forward 6
+forward 4
+forward 1
+down 7
+down 4
+forward 2
+down 6
+forward 3
+down 5
+forward 3
+forward 4
+forward 4
+forward 9
+down 5
+forward 7
+forward 7
+forward 9
+down 1
+up 6
+forward 1
+down 9
+forward 3
+down 7
+up 8
+up 6
+down 7
+forward 2
+down 9
+forward 9
+forward 6
+down 9
+forward 6
+down 8
+forward 1
+up 6
+down 1
+forward 6
+down 9
+forward 6
+forward 7
+forward 3
+forward 8
+forward 5
+forward 8
+down 9
+down 2
+forward 3
+down 3
+up 4
+down 4
+down 3
+forward 3
+forward 3
+down 5
+forward 5
+forward 1
+down 9
+down 3
+up 7
+forward 9
+up 1
+down 1
+down 6
+up 1
+forward 2
diff --git a/02/src/main.rs b/02/src/main.rs
new file mode 100644
index 0000000..92ba083
--- /dev/null
+++ b/02/src/main.rs
@@ -0,0 +1,70 @@
+use advent_lib::prelude::*;
+
+
+fn main() -> Result<()> {
+  let mut args = std::env::args();
+  if args.len() != 2 {
+    eprintln!("Usage: advent input");
+  }
+  let _ = args.next();
+  let filename = args.next().unwrap();
+
+  let input = advent_lib::read_lines_file(&filename)?;
+
+  {
+    let mut depth = 0;
+    let mut horizontal = 0;
+
+    for line in &input {
+      let mut words = line.split(' ');
+      let command = words.next().unwrap();
+      let parameter = words.next().unwrap().parse::<i64>().unwrap();
+
+      match command {
+        "forward" => {
+          horizontal += parameter;
+        },
+        "down" => {
+          depth += parameter;
+        },
+        "up" => {
+          depth -= parameter;
+        },
+        _ => { },
+      }
+    }
+
+    println!("{}", horizontal * depth);
+  }
+
+  {
+    let mut aim = 0;
+    let mut depth = 0;
+    let mut horizontal = 0;
+
+    for line in &input {
+      let mut words = line.split(' ');
+      let command = words.next().unwrap();
+      let parameter = words.next().unwrap().parse::<i64>().unwrap();
+
+      match command {
+        "forward" => {
+          horizontal += parameter;
+          depth += aim * parameter;
+        },
+        "down" => {
+          aim += parameter;
+        },
+        "up" => {
+          aim -= parameter;
+        },
+        _ => { },
+      }
+    }
+
+    println!("{}", horizontal * depth);
+  }
+
+  Ok(())
+}
+
diff --git a/02/tests/main.rs b/02/tests/main.rs
new file mode 100644
index 0000000..b74d88d
--- /dev/null
+++ b/02/tests/main.rs
@@ -0,0 +1,17 @@
+use assert_cmd::prelude::*;
+//use predicates::prelude::*;
+use std::process::Command;
+
+
+#[test]
+fn personal_input() -> Result<(), Box<dyn std::error::Error>> {
+  let mut command = Command::cargo_bin("advent_02")?;
+
+  command.arg("input");
+  command.assert().success().stdout(
+      "1813801\n\
+      1960569556\n");
+
+  Ok(())
+}
+