summaryrefslogtreecommitdiff
path: root/day2/src
diff options
context:
space:
mode:
Diffstat (limited to 'day2/src')
-rw-r--r--day2/src/main.rs34
1 files changed, 34 insertions, 0 deletions
diff --git a/day2/src/main.rs b/day2/src/main.rs
new file mode 100644
index 0000000..e0153a3
--- /dev/null
+++ b/day2/src/main.rs
@@ -0,0 +1,34 @@
+use std::fs::File;
+use std::io::prelude::*;
+use std::io::BufReader;
+
+fn main() {
+ let file = File::open("input.txt").unwrap();
+ let reader = BufReader::new(&file);
+ let tokens: Vec<String> = reader.lines().map(|x| x.unwrap()).collect::<Vec<String>>();
+ let mut xpos: u32 = 0;
+ let mut ypos: u32 = 0;
+ let mut aim: u32 = 0;
+
+ for line in tokens {
+ let command: Vec<&str> = line.split(" ").collect();
+ let (action, value) = (command[0], command[1].parse::<u32>().unwrap());
+
+ match action {
+ "forward" => {
+ xpos += value;
+ ypos += aim * value;
+ }
+ "down" => {
+ // ypos += value;
+ aim += value;
+ }
+ "up" => {
+ // ypos -= value;
+ aim -= value;
+ }
+ _ => {}
+ }
+ }
+ println!("{}", ypos * xpos);
+}