From 73246304f5a446db83e09f1b4295f7103bc14d7a Mon Sep 17 00:00:00 2001 From: kirbylife Date: Mon, 1 Dec 2025 22:33:47 -0600 Subject: [PATCH] Day 1 part 1 --- day-1/Cargo.toml | 6 ++++++ day-1/src/main.rs | 53 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 day-1/Cargo.toml create mode 100644 day-1/src/main.rs diff --git a/day-1/Cargo.toml b/day-1/Cargo.toml new file mode 100644 index 0000000..3061f8e --- /dev/null +++ b/day-1/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "day-1" +version = "0.1.0" +edition = "2024" + +[dependencies] diff --git a/day-1/src/main.rs b/day-1/src/main.rs new file mode 100644 index 0000000..7b63499 --- /dev/null +++ b/day-1/src/main.rs @@ -0,0 +1,53 @@ +use std::fs::File; +use std::io::prelude::*; + +#[derive(Debug)] +enum Direction { + LEFT, + RIGHT, +} + +impl Direction { + fn from_str(s: &str) -> Self { + match s { + "L" => Direction::LEFT, + "R" => Direction::RIGHT, + _ => Direction::RIGHT, + } + } +} + +fn parse_input() -> Vec<(Direction, i32)> { + let mut file = File::open("input.txt").unwrap(); + let mut buffer = String::new(); + file.read_to_string(&mut buffer).unwrap(); + return buffer + .lines() + .map(|line| { + let (dir, steps) = line.split_at(1); + (Direction::from_str(dir), steps.parse().unwrap()) + }) + .collect::>(); +} + +fn part_1() { + let input = parse_input(); + let mut dial = 50; + let mut counter = 0; + for (dir, steps) in input { + dial += match dir { + Direction::LEFT => steps * -1, + Direction::RIGHT => steps, + }; + dial = dial % 100; + if dial == 0 { + counter += 1; + } + } + println!("{}", counter); +} + +fn main() { + println!("Part 1:"); + part_1(); +}