Added day 1 part 1

Started day 8
Started day 8
This commit is contained in:
2025-12-14 12:54:38 -06:00
parent bf04d91590
commit ea61cbb0c2
4 changed files with 195 additions and 13 deletions

58
src/day1/mod.rs Normal file
View File

@@ -0,0 +1,58 @@
use std::{fs::File, io::Read};
fn read_file(file: &str) -> String {
let mut directory = "/home/jason/Programming/Rust/aoc2025/src/day1/".to_owned();
directory.push_str(file);
let mut handle = File::open(directory).unwrap();
let mut file = String::new();
handle.read_to_string(&mut file).unwrap();
file
}
pub fn part_1(file: &str) -> u64 {
let input = read_file(file);
let mut pos = 50;
let mut count = 0;
for i in input.lines() {
let mut char_iter = i.chars();
let dir = char_iter.next().unwrap();
let dist = char_iter.collect::<String>().parse::<i32>().unwrap();
match dir {
'L' => {
pos -= dist;
},
'R' => {
pos += dist;
},
_ => panic!(),
}
while pos < 0 {
pos += 100;
}
while pos > 99 {
pos -= 100;
}
if pos == 0 {
count += 1;
}
}
count
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn day_one_part_one() {
assert_eq!(part_1("test.txt"), 3);
}
}

View File

@@ -1,4 +1,4 @@
use std::{fs::File, io::Read};
use std::{fs::{File, read}, io::Read};
fn read_file(file: &str) -> String {
let mut directory = "/home/jason/Programming/Rust/aoc2025/src/day3/".to_owned();
@@ -22,6 +22,8 @@ pub fn part_1(file: &str) -> u64{
batteries.push(rowvec);
}
let mut joltages: Vec<u8> = Vec::new();
for bank in batteries {
let mut first_digit = 0;
let mut second_digit = 0;
@@ -31,12 +33,49 @@ pub fn part_1(file: &str) -> u64{
let current = bank_iter.next().unwrap();
let next = bank_iter.peek();
match next {
Some(_) => {},
None => {},
Some(_) => {
if *current > first_digit {
first_digit = *current;
second_digit = 0;
} else if *current > second_digit {
second_digit = *current;
}
},
None => {
if *current > second_digit {
second_digit = *current;
}
break;
},
}
}
let output = first_digit*10 + second_digit;
joltages.push(output);
}
0
joltages.iter().fold(0, |acc, x| *x as u64 + acc)
}
fn part_2(file: &str) -> u64 {
let data = read_file(file);
let mut batteries: Vec<Vec<u8>> = Vec::new();
for row in data.lines() {
let mut rowvec = Vec::new();
for c in row.chars() {
rowvec.push(c.to_digit(10).unwrap() as u8);
}
batteries.push(rowvec);
}
let mut joltages: Vec<u32> = Vec::new();
for i in batteries {
}
joltages.iter().fold(0, |acc, x| *x as u64 + acc)
}
#[cfg(test)]
@@ -44,7 +83,7 @@ mod tests {
use super::*;
#[test]
fn day_three_part_1() {
fn day_three_part_one() {
assert_eq!(part_1("test.txt"), 357);
}
}

62
src/day8/mod.rs Normal file
View File

@@ -0,0 +1,62 @@
use std::{fs::File, io::Read};
//test 0-1_000
//input 0-100_000
fn read_file(file: &str) -> String {
let mut directory = "/home/jason/Programming/Rust/aoc2025/src/day8/".to_owned();
directory.push_str(file);
let mut handle = File::open(directory).unwrap();
let mut file = String::new();
handle.read_to_string(&mut file).unwrap();
file
}
fn parse_file(data: String) -> Vec<Point> {
let mut points = Vec::new();
for i in data.lines() {
let mut nums = i.split(',');
let x = nums.next().unwrap().parse().unwrap();
let y = nums.next().unwrap().parse().unwrap();
let z = nums.next().unwrap().parse().unwrap();
points.push(Point{x,y,z});
}
points
}
#[derive(Debug)]
struct Point {
x: u32,
y: u32,
z: u32,
}
fn part_1(file: &str) -> u64 {
let grid_factor = 100;
let num_connections;
let grid_max;
if file == "test.txt" {
num_connections = 10;
grid_max = 1000;
} else {
num_connections = 1000;
grid_max = 100000;
}
let data = parse_file(read_file(file));
0
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn day_eight_p_1() {
assert_eq!(part_1("input.txt"), 40);
}
}

View File

@@ -1,15 +1,38 @@
use std::env;
mod day1;
mod day3;
mod day6;
mod day7;
mod day8;
fn main() {
/*let d6p1 = day6::part_1("input.txt");
println!("Day 6 Part 1 Solution: {}", d6p1);
let d6p2 = day6::part_2("input.txt");
println!("Day 6 Part 2 Solution: {}", d6p2);*/
let d7p1 = day7::part_1("input.txt");
println!("Day 7 Part 1 Solution: {}", d7p1);
let d7p2 = day7::part_2("input.txt");
println!("Day 7 Part 2 Solution: {}", d7p2);
let envargs = env::args().collect::<Vec<String>>();
if envargs.contains(&"--day1".to_owned()) | envargs.contains(&"--all".to_owned()) {
let d3p1 = day1::part_1("input.txt");
println!("Day 1 Part 1 Solution: {}", d3p1);
//let d3p2 = day3::part_2("input.txt");
//println!("Day 3 Part 2 Solution: {}", d3p2);
}
if envargs.contains(&"--day3".to_owned()) | envargs.contains(&"--all".to_owned()) {
let d3p1 = day3::part_1("input.txt");
println!("Day 3 Part 1 Solution: {}", d3p1);
//let d3p2 = day3::part_2("input.txt");
//println!("Day 3 Part 2 Solution: {}", d3p2);
}
if envargs.contains(&"--day6".to_owned()) | envargs.contains(&"--all".to_owned()) {
let d6p1 = day6::part_1("input.txt");
println!("Day 6 Part 1 Solution: {}", d6p1);
let d6p2 = day6::part_2("input.txt");
println!("Day 6 Part 2 Solution: {}", d6p2);
}
if envargs.contains(&"--day7".to_owned()) | envargs.contains(&"--all".to_owned()) {
let d7p1 = day7::part_1("input.txt");
println!("Day 7 Part 1 Solution: {}", d7p1);
let d7p2 = day7::part_2("input.txt");
println!("Day 7 Part 2 Solution: {}", d7p2);
}
}