From 5f574cf344f579787f3ba6a65831a8e80532acbd Mon Sep 17 00:00:00 2001 From: Santo Cariotti Date: Mon, 6 Dec 2021 22:19:46 +0100 Subject: Add day2 --- Cargo.toml | 2 +- day2/Cargo.toml | 8 + day2/input.txt | 1000 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ day2/src/main.rs | 34 ++ 4 files changed, 1043 insertions(+), 1 deletion(-) create mode 100644 day2/Cargo.toml create mode 100644 day2/input.txt create mode 100644 day2/src/main.rs diff --git a/Cargo.toml b/Cargo.toml index f75e3a9..ddbf747 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,4 +4,4 @@ version = "0.1.0" edition = "2021" [workspace] -members = ["day1"] +members = ["day1", "day2"] diff --git a/day2/Cargo.toml b/day2/Cargo.toml new file mode 100644 index 0000000..8aa34bb --- /dev/null +++ b/day2/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "day2" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/day2/input.txt b/day2/input.txt new file mode 100644 index 0000000..9e714f9 --- /dev/null +++ b/day2/input.txt @@ -0,0 +1,1000 @@ +forward 2 +down 8 +down 1 +up 7 +forward 4 +down 4 +down 3 +forward 2 +forward 5 +forward 2 +forward 7 +forward 8 +down 7 +forward 6 +forward 1 +down 8 +down 8 +up 9 +down 9 +forward 1 +up 1 +forward 6 +forward 7 +down 7 +forward 4 +forward 2 +forward 1 +forward 3 +forward 8 +forward 4 +up 6 +down 2 +forward 4 +down 3 +up 3 +up 2 +up 3 +forward 8 +down 5 +down 8 +down 5 +down 4 +down 2 +up 1 +forward 6 +forward 6 +forward 8 +up 5 +down 5 +forward 8 +forward 7 +down 9 +down 7 +down 6 +down 3 +forward 3 +up 7 +forward 2 +up 6 +forward 7 +forward 9 +down 9 +forward 3 +down 2 +down 2 +down 7 +down 7 +forward 8 +down 7 +forward 9 +up 7 +down 4 +down 8 +forward 2 +forward 2 +up 1 +forward 8 +down 5 +forward 8 +forward 4 +up 1 +forward 2 +forward 2 +forward 2 +down 9 +down 7 +down 9 +forward 9 +forward 4 +up 7 +down 4 +forward 9 +forward 8 +up 5 +up 1 +down 1 +down 9 +down 6 +up 8 +forward 2 +forward 7 +up 7 +forward 7 +forward 6 +down 6 +forward 8 +up 6 +forward 7 +down 7 +forward 4 +forward 9 +up 9 +up 8 +forward 8 +forward 3 +up 1 +up 4 +down 4 +up 9 +up 8 +forward 6 +down 2 +down 2 +up 4 +forward 4 +forward 1 +down 8 +forward 6 +down 5 +forward 6 +down 8 +up 1 +forward 1 +up 9 +down 8 +up 3 +up 9 +forward 9 +forward 2 +down 2 +up 6 +up 6 +forward 8 +up 3 +down 3 +forward 5 +up 2 +forward 1 +forward 1 +forward 8 +down 4 +forward 8 +forward 7 +down 8 +forward 7 +down 7 +down 2 +down 1 +down 7 +up 9 +down 5 +up 1 +forward 7 +down 5 +down 9 +down 2 +down 8 +down 4 +forward 2 +forward 2 +forward 1 +down 6 +up 7 +forward 2 +down 1 +down 5 +forward 3 +forward 8 +down 4 +up 2 +up 9 +up 7 +forward 7 +forward 4 +up 8 +up 3 +up 4 +forward 6 +down 7 +forward 7 +up 6 +down 9 +up 6 +forward 4 +up 3 +down 3 +up 6 +down 9 +down 6 +forward 7 +forward 9 +forward 2 +down 6 +up 3 +up 9 +forward 9 +forward 8 +up 4 +up 5 +forward 6 +down 5 +up 4 +up 9 +down 8 +forward 5 +up 5 +forward 7 +forward 6 +down 8 +down 5 +down 2 +up 5 +down 8 +forward 7 +forward 7 +up 6 +forward 3 +down 8 +forward 5 +forward 8 +down 7 +forward 6 +down 2 +forward 2 +forward 8 +down 4 +forward 5 +forward 7 +forward 5 +forward 8 +forward 9 +forward 6 +down 6 +up 7 +down 9 +forward 7 +forward 1 +up 2 +forward 8 +down 1 +up 9 +forward 7 +down 2 +up 2 +forward 5 +down 4 +down 3 +up 8 +up 6 +forward 3 +up 4 +forward 3 +forward 1 +forward 1 +up 9 +down 2 +down 9 +up 4 +forward 4 +forward 4 +forward 2 +forward 5 +forward 9 +forward 7 +up 4 +up 5 +down 5 +forward 9 +down 1 +forward 2 +down 6 +forward 9 +down 4 +down 2 +forward 2 +up 7 +forward 7 +forward 8 +up 9 +forward 3 +up 1 +down 5 +forward 5 +down 1 +up 5 +forward 4 +forward 5 +up 3 +down 4 +up 6 +up 1 +down 2 +forward 6 +down 8 +up 9 +down 7 +forward 9 +down 8 +forward 3 +forward 8 +down 1 +down 7 +forward 6 +up 6 +down 1 +down 5 +forward 6 +down 7 +down 2 +forward 6 +forward 2 +forward 8 +forward 7 +forward 2 +down 7 +up 2 +down 7 +forward 8 +forward 8 +forward 2 +forward 4 +down 1 +down 6 +down 1 +down 4 +down 4 +down 2 +down 7 +up 5 +up 5 +down 1 +forward 3 +up 1 +down 3 +forward 9 +forward 4 +forward 7 +down 4 +down 4 +down 2 +forward 2 +forward 1 +forward 9 +down 1 +down 4 +down 1 +forward 4 +up 8 +forward 3 +down 6 +forward 5 +forward 9 +forward 1 +up 8 +down 7 +down 8 +forward 4 +down 4 +up 5 +down 3 +forward 3 +down 6 +down 1 +down 9 +forward 8 +up 5 +down 7 +up 7 +forward 3 +up 5 +up 7 +down 4 +up 2 +down 2 +down 8 +up 6 +down 4 +up 1 +down 8 +down 4 +forward 7 +down 4 +up 3 +down 9 +forward 3 +up 4 +up 1 +up 5 +down 4 +forward 4 +forward 4 +down 2 +down 3 +down 4 +forward 2 +down 9 +down 9 +down 6 +forward 5 +forward 7 +down 3 +forward 2 +up 8 +down 6 +down 8 +down 2 +up 9 +down 1 +forward 8 +forward 1 +forward 8 +up 4 +up 1 +down 8 +up 2 +forward 5 +down 3 +forward 5 +forward 4 +forward 1 +down 9 +forward 2 +forward 5 +forward 4 +forward 3 +down 7 +up 9 +forward 7 +up 8 +forward 3 +forward 3 +down 5 +forward 7 +forward 5 +down 4 +forward 6 +down 6 +up 3 +down 3 +forward 7 +forward 8 +up 3 +up 8 +forward 8 +up 4 +forward 5 +up 4 +down 7 +forward 4 +down 8 +down 6 +forward 7 +down 4 +up 7 +down 6 +up 5 +down 2 +forward 7 +down 7 +up 3 +up 3 +down 3 +down 5 +forward 3 +forward 5 +forward 8 +down 3 +down 8 +forward 3 +down 1 +forward 4 +up 5 +forward 8 +up 1 +up 4 +down 4 +forward 1 +forward 6 +up 7 +up 1 +up 7 +down 5 +forward 8 +down 1 +forward 1 +forward 6 +up 9 +up 6 +down 4 +forward 5 +down 1 +forward 7 +down 8 +up 3 +down 9 +down 1 +up 7 +up 6 +forward 8 +down 9 +down 4 +forward 4 +up 7 +down 3 +forward 5 +forward 8 +up 5 +down 7 +up 2 +forward 3 +forward 3 +forward 4 +down 1 +forward 5 +forward 7 +up 7 +forward 7 +forward 1 +forward 3 +forward 9 +down 3 +forward 5 +down 9 +down 7 +down 4 +down 8 +up 3 +down 1 +up 5 +down 5 +forward 2 +down 6 +down 5 +forward 2 +forward 6 +down 6 +up 6 +down 8 +up 1 +forward 4 +forward 2 +forward 1 +up 1 +forward 5 +forward 3 +forward 7 +down 9 +forward 3 +down 9 +up 5 +down 7 +down 2 +down 3 +up 5 +up 3 +down 2 +forward 4 +forward 1 +down 3 +up 4 +down 8 +down 1 +forward 6 +down 3 +forward 9 +down 7 +down 3 +down 4 +down 5 +up 1 +forward 8 +forward 2 +up 3 +up 7 +up 1 +forward 3 +forward 9 +up 5 +forward 6 +down 8 +down 9 +down 5 +forward 6 +forward 3 +forward 8 +forward 7 +forward 9 +forward 2 +up 9 +forward 8 +down 2 +down 6 +down 9 +down 5 +forward 1 +down 7 +forward 2 +down 4 +down 1 +up 1 +down 2 +forward 5 +forward 8 +down 9 +up 6 +forward 8 +forward 3 +up 6 +up 2 +forward 8 +down 8 +up 1 +down 6 +down 2 +down 6 +forward 5 +forward 6 +down 4 +forward 1 +down 4 +up 7 +forward 4 +up 1 +forward 9 +forward 7 +up 3 +down 7 +down 4 +forward 3 +forward 8 +forward 6 +forward 6 +up 1 +up 2 +up 8 +down 7 +forward 8 +down 5 +forward 6 +down 1 +down 9 +down 2 +forward 6 +up 3 +down 5 +down 6 +forward 1 +forward 2 +down 3 +forward 8 +forward 1 +up 5 +down 8 +down 4 +up 9 +up 2 +forward 7 +forward 9 +up 8 +up 6 +forward 1 +down 7 +up 1 +down 3 +forward 2 +forward 3 +down 3 +down 2 +forward 3 +down 7 +forward 3 +forward 7 +forward 7 +down 8 +down 4 +forward 3 +forward 4 +down 7 +down 9 +down 4 +down 2 +forward 7 +up 8 +down 4 +down 3 +forward 9 +down 5 +up 6 +up 2 +down 5 +down 6 +forward 2 +forward 8 +down 1 +forward 6 +up 7 +down 6 +forward 4 +down 2 +down 5 +down 9 +forward 7 +up 4 +forward 9 +up 7 +down 4 +down 6 +up 9 +forward 1 +up 7 +down 5 +forward 3 +forward 3 +down 7 +down 1 +down 7 +down 7 +down 1 +forward 8 +forward 9 +forward 8 +down 9 +down 8 +down 5 +down 3 +forward 4 +forward 1 +down 1 +forward 1 +down 7 +forward 7 +forward 3 +down 8 +forward 3 +forward 9 +forward 8 +down 7 +forward 8 +down 2 +up 5 +forward 7 +forward 4 +down 2 +up 6 +up 8 +forward 7 +down 9 +up 3 +forward 4 +up 9 +up 5 +up 5 +up 6 +down 4 +down 5 +up 5 +forward 7 +forward 6 +down 4 +forward 5 +forward 4 +up 7 +forward 8 +down 2 +forward 1 +down 9 +down 8 +forward 7 +down 7 +down 1 +forward 9 +down 7 +forward 6 +down 2 +up 9 +forward 1 +up 9 +down 3 +up 9 +down 1 +forward 1 +down 1 +up 6 +down 8 +up 2 +down 3 +forward 1 +down 4 +up 5 +down 5 +down 4 +forward 5 +forward 4 +down 9 +up 7 +down 7 +forward 7 +forward 6 +forward 8 +down 8 +forward 8 +down 1 +down 1 +down 8 +down 2 +up 2 +up 1 +forward 5 +down 1 +up 5 +up 2 +down 6 +up 8 +forward 5 +down 8 +down 1 +up 5 +down 1 +forward 4 +down 6 +down 4 +forward 2 +forward 2 +down 1 +up 4 +up 8 +down 6 +down 2 +forward 5 +forward 8 +forward 7 +down 5 +down 7 +down 3 +forward 6 +down 3 +down 3 +forward 6 +forward 6 +forward 6 +up 7 +forward 1 +down 5 +down 2 +up 8 +forward 6 +down 7 +down 6 +forward 1 +up 5 +down 4 +up 9 +forward 3 +up 3 +forward 9 +forward 9 +forward 7 +forward 5 +down 9 +forward 1 +forward 6 +up 8 +down 7 +forward 9 +forward 5 +up 4 +down 8 +forward 8 +forward 4 +down 9 +up 2 +forward 5 +forward 8 +down 8 +down 9 +down 9 +forward 4 +forward 8 +down 5 +down 5 +forward 5 +forward 5 +up 9 +up 7 +forward 3 +up 4 +down 8 +up 6 +up 6 +down 4 +down 3 +forward 2 +forward 9 +down 4 +down 2 +forward 4 +up 9 +forward 1 +down 8 +down 9 +down 9 +down 3 +forward 1 +down 5 +up 9 +forward 6 +up 4 +forward 2 +forward 2 +forward 4 +down 9 +up 5 +up 1 +down 6 +forward 7 +down 8 +forward 4 +forward 9 +up 9 +up 4 +down 5 +down 3 +forward 2 +down 8 +down 6 +forward 3 +down 2 +forward 6 +up 2 +forward 6 +down 7 +up 4 +forward 1 +forward 4 +up 4 +forward 6 +forward 8 +down 7 +down 6 +up 7 +down 2 +down 4 +down 5 +forward 1 +up 4 +forward 8 +forward 6 +down 8 +up 5 +up 2 +up 9 +up 5 +forward 6 +down 4 +up 3 +down 8 +down 6 +down 2 +up 3 +up 5 +down 1 +forward 9 +up 8 +up 2 +down 3 +forward 6 +down 1 +forward 5 +down 3 +up 1 +up 2 +down 5 +down 7 +forward 8 +down 8 +up 9 +forward 3 +down 8 +down 8 +forward 1 +down 4 +down 4 +forward 3 +up 6 +down 3 +down 7 +down 7 +up 1 +forward 3 +forward 2 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 = 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