diff --git a/2025/inputs/01.txt b/2025/inputs/01.txt new file mode 100644 index 0000000..53287c7 --- /dev/null +++ b/2025/inputs/01.txt @@ -0,0 +1,10 @@ +L68 +L30 +R48 +L5 +R60 +L55 +L1 +L99 +R14 +L82 diff --git a/2025/rust/.envrc b/2025/rust/.envrc new file mode 100644 index 0000000..4196168 --- /dev/null +++ b/2025/rust/.envrc @@ -0,0 +1 @@ +use flake .#rust diff --git a/2025/rust/day-01/Cargo.lock b/2025/rust/day-01/Cargo.lock new file mode 100644 index 0000000..6e11d14 --- /dev/null +++ b/2025/rust/day-01/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "day-01" +version = "0.1.0" diff --git a/2025/rust/day-01/Cargo.toml b/2025/rust/day-01/Cargo.toml new file mode 100644 index 0000000..c43f1c8 --- /dev/null +++ b/2025/rust/day-01/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "day-01" +version = "0.1.0" +edition = "2024" + +[dependencies] diff --git a/2025/rust/day-01/src/main.rs b/2025/rust/day-01/src/main.rs new file mode 100644 index 0000000..6f15cf3 --- /dev/null +++ b/2025/rust/day-01/src/main.rs @@ -0,0 +1,45 @@ +use std::fs::{self}; + +fn main() { + let rotations = read_input(); + + println!("Password: {}", count_neutral_positions(rotations)); +} + +fn read_input() -> Vec { + let contents = fs::read_to_string("../../inputs/01.txt").unwrap(); + let lines = contents.lines(); + + let mut rotations = vec![]; + + for line in lines { + let (direction, distance) = line.split_at(1); + + let distance = distance.parse::().unwrap(); + + let rotation = match direction { + "L" => distance * -1, + "R" => distance, + _ => panic!(), + }; + + rotations.push(rotation); + } + + rotations +} + +fn count_neutral_positions(rotations: Vec) -> i32 { + let mut counter = 0; + let mut position = 50; + + for rotation in rotations { + position = (position + rotation) % 100; + + if position == 0 { + counter += 1; + } + } + + counter +}