From cf6303a5bc1558ebdb7b467da38f74cd3ac3a9b1 Mon Sep 17 00:00:00 2001 From: Santo Cariotti Date: Mon, 5 Dec 2022 19:46:06 +0100 Subject: Add 2022 --- day2/src/main.rs | 34 ---------------------------------- 1 file changed, 34 deletions(-) delete mode 100644 day2/src/main.rs (limited to 'day2/src/main.rs') diff --git a/day2/src/main.rs b/day2/src/main.rs deleted file mode 100644 index e0153a3..0000000 --- a/day2/src/main.rs +++ /dev/null @@ -1,34 +0,0 @@ -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 = reader.lines().map(|x| x.unwrap()).collect::>(); - 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::().unwrap()); - - match action { - "forward" => { - xpos += value; - ypos += aim * value; - } - "down" => { - // ypos += value; - aim += value; - } - "up" => { - // ypos -= value; - aim -= value; - } - _ => {} - } - } - println!("{}", ypos * xpos); -} -- cgit v1.2.3-18-g5258