This commit is contained in:
Rh4096 2024-12-07 11:03:53 +07:00
parent c38b6b6087
commit 289ae15cc5
21 changed files with 480 additions and 25 deletions

View file

@ -1 +1,25 @@
use std::{fs::read_to_string, path::Path};
use super::AocSolution;
use crate::utils::Result;
pub struct AocDayTenSolution; pub struct AocDayTenSolution;
impl AocSolution for AocDayTenSolution {
type Output = u64;
fn get_input(&self, path: Option<&Path>) -> Result<String> {
Ok(match path {
Some(p) => read_to_string(p)?,
None => read_to_string("./input/day_day_10.txt")?,
})
}
fn part_one(&self, input: &str) -> Result<Self::Output> {
todo!()
}
fn part_two(&self, input: &str) -> Result<Self::Output> {
todo!()
}
}

View file

@ -1 +1,25 @@
use std::{fs::read_to_string, path::Path};
use super::AocSolution;
use crate::utils::Result;
pub struct AocDayElevenSolution; pub struct AocDayElevenSolution;
impl AocSolution for AocDayElevenSolution {
type Output = u64;
fn get_input(&self, path: Option<&Path>) -> Result<String> {
Ok(match path {
Some(p) => read_to_string(p)?,
None => read_to_string("./input/day_day_11.txt")?,
})
}
fn part_one(&self, input: &str) -> Result<Self::Output> {
todo!()
}
fn part_two(&self, input: &str) -> Result<Self::Output> {
todo!()
}
}

View file

@ -1 +1,25 @@
use std::{fs::read_to_string, path::Path};
use super::AocSolution;
use crate::utils::Result;
pub struct AocDayTwelveSolution; pub struct AocDayTwelveSolution;
impl AocSolution for AocDayTwelveSolution {
type Output = u64;
fn get_input(&self, path: Option<&Path>) -> Result<String> {
Ok(match path {
Some(p) => read_to_string(p)?,
None => read_to_string("./input/day_day_12.txt")?,
})
}
fn part_one(&self, input: &str) -> Result<Self::Output> {
todo!()
}
fn part_two(&self, input: &str) -> Result<Self::Output> {
todo!()
}
}

View file

@ -1 +1,25 @@
use std::{fs::read_to_string, path::Path};
use super::AocSolution;
use crate::utils::Result;
pub struct AocDayThirteenSolution; pub struct AocDayThirteenSolution;
impl AocSolution for AocDayThirteenSolution {
type Output = u64;
fn get_input(&self, path: Option<&Path>) -> Result<String> {
Ok(match path {
Some(p) => read_to_string(p)?,
None => read_to_string("./input/day_day_13.txt")?,
})
}
fn part_one(&self, input: &str) -> Result<Self::Output> {
todo!()
}
fn part_two(&self, input: &str) -> Result<Self::Output> {
todo!()
}
}

View file

@ -1 +1,25 @@
use std::{fs::read_to_string, path::Path};
use super::AocSolution;
use crate::utils::Result;
pub struct AocDayFourteenSolution; pub struct AocDayFourteenSolution;
impl AocSolution for AocDayFourteenSolution {
type Output = u64;
fn get_input(&self, path: Option<&Path>) -> Result<String> {
Ok(match path {
Some(p) => read_to_string(p)?,
None => read_to_string("./input/day_day_14.txt")?,
})
}
fn part_one(&self, input: &str) -> Result<Self::Output> {
todo!()
}
fn part_two(&self, input: &str) -> Result<Self::Output> {
todo!()
}
}

View file

@ -1 +1,25 @@
use std::{fs::read_to_string, path::Path};
use super::AocSolution;
use crate::utils::Result;
pub struct AocDayFifteenSolution; pub struct AocDayFifteenSolution;
impl AocSolution for AocDayFifteenSolution {
type Output = u64;
fn get_input(&self, path: Option<&Path>) -> Result<String> {
Ok(match path {
Some(p) => read_to_string(p)?,
None => read_to_string("./input/day_day_15.txt")?,
})
}
fn part_one(&self, input: &str) -> Result<Self::Output> {
todo!()
}
fn part_two(&self, input: &str) -> Result<Self::Output> {
todo!()
}
}

View file

@ -1 +1,25 @@
use std::{fs::read_to_string, path::Path};
use super::AocSolution;
use crate::utils::Result;
pub struct AocDaySixteenSolution; pub struct AocDaySixteenSolution;
impl AocSolution for AocDaySixteenSolution {
type Output = u64;
fn get_input(&self, path: Option<&Path>) -> Result<String> {
Ok(match path {
Some(p) => read_to_string(p)?,
None => read_to_string("./input/day_day_16.txt")?,
})
}
fn part_one(&self, input: &str) -> Result<Self::Output> {
todo!()
}
fn part_two(&self, input: &str) -> Result<Self::Output> {
todo!()
}
}

View file

@ -1 +1,25 @@
use std::{fs::read_to_string, path::Path};
use super::AocSolution;
use crate::utils::Result;
pub struct AocDaySeventeenSolution; pub struct AocDaySeventeenSolution;
impl AocSolution for AocDaySeventeenSolution {
type Output = u64;
fn get_input(&self, path: Option<&Path>) -> Result<String> {
Ok(match path {
Some(p) => read_to_string(p)?,
None => read_to_string("./input/day_day_17.txt")?,
})
}
fn part_one(&self, input: &str) -> Result<Self::Output> {
todo!()
}
fn part_two(&self, input: &str) -> Result<Self::Output> {
todo!()
}
}

View file

@ -1 +1,25 @@
use std::{fs::read_to_string, path::Path};
use super::AocSolution;
use crate::utils::Result;
pub struct AocDayEighteenSolution; pub struct AocDayEighteenSolution;
impl AocSolution for AocDayEighteenSolution {
type Output = u64;
fn get_input(&self, path: Option<&Path>) -> Result<String> {
Ok(match path {
Some(p) => read_to_string(p)?,
None => read_to_string("./input/day_day_18.txt")?,
})
}
fn part_one(&self, input: &str) -> Result<Self::Output> {
todo!()
}
fn part_two(&self, input: &str) -> Result<Self::Output> {
todo!()
}
}

View file

@ -1 +1,25 @@
use std::{fs::read_to_string, path::Path};
use super::AocSolution;
use crate::utils::Result;
pub struct AocDayNineteenSolution; pub struct AocDayNineteenSolution;
impl AocSolution for AocDayNineteenSolution {
type Output = u64;
fn get_input(&self, path: Option<&Path>) -> Result<String> {
Ok(match path {
Some(p) => read_to_string(p)?,
None => read_to_string("./input/day_day_19.txt")?,
})
}
fn part_one(&self, input: &str) -> Result<Self::Output> {
todo!()
}
fn part_two(&self, input: &str) -> Result<Self::Output> {
todo!()
}
}

View file

@ -1 +1,25 @@
use std::{fs::read_to_string, path::Path};
use super::AocSolution;
use crate::utils::Result;
pub struct AocDayTwentySolution; pub struct AocDayTwentySolution;
impl AocSolution for AocDayTwentySolution {
type Output = u64;
fn get_input(&self, path: Option<&Path>) -> Result<String> {
Ok(match path {
Some(p) => read_to_string(p)?,
None => read_to_string("./input/day_day_20.txt")?,
})
}
fn part_one(&self, input: &str) -> Result<Self::Output> {
todo!()
}
fn part_two(&self, input: &str) -> Result<Self::Output> {
todo!()
}
}

View file

@ -1 +1,25 @@
use std::{fs::read_to_string, path::Path};
use super::AocSolution;
use crate::utils::Result;
pub struct AocDayTwentyOneSolution; pub struct AocDayTwentyOneSolution;
impl AocSolution for AocDayTwentyOneSolution {
type Output = u64;
fn get_input(&self, path: Option<&Path>) -> Result<String> {
Ok(match path {
Some(p) => read_to_string(p)?,
None => read_to_string("./input/day_day_21.txt")?,
})
}
fn part_one(&self, input: &str) -> Result<Self::Output> {
todo!()
}
fn part_two(&self, input: &str) -> Result<Self::Output> {
todo!()
}
}

View file

@ -1 +1,26 @@
use std::{fs::read_to_string, path::Path};
use super::AocSolution;
use crate::utils::Result;
pub struct AocDayTwentyTwoSolution; pub struct AocDayTwentyTwoSolution;
impl AocSolution for AocDayTwentyTwoSolution {
type Output = u64;
fn get_input(&self, path: Option<&Path>) -> Result<String> {
Ok(match path {
Some(p) => read_to_string(p)?,
None => read_to_string("./input/day_day_22.txt")?,
})
}
fn part_one(&self, input: &str) -> Result<Self::Output> {
todo!()
}
fn part_two(&self, input: &str) -> Result<Self::Output> {
todo!()
}
}

View file

@ -1 +1,25 @@
use std::{fs::read_to_string, path::Path};
use super::AocSolution;
use crate::utils::Result;
pub struct AocDayTwentyThreeSolution; pub struct AocDayTwentyThreeSolution;
impl AocSolution for AocDayTwentyThreeSolution {
type Output = u64;
fn get_input(&self, path: Option<&Path>) -> Result<String> {
Ok(match path {
Some(p) => read_to_string(p)?,
None => read_to_string("./input/day_day_23.txt")?,
})
}
fn part_one(&self, input: &str) -> Result<Self::Output> {
todo!()
}
fn part_two(&self, input: &str) -> Result<Self::Output> {
todo!()
}
}

View file

@ -1 +1,25 @@
use std::{fs::read_to_string, path::Path};
use super::AocSolution;
use crate::utils::Result;
pub struct AocDayTwentyFourSolution; pub struct AocDayTwentyFourSolution;
impl AocSolution for AocDayTwentyFourSolution {
type Output = u64;
fn get_input(&self, path: Option<&Path>) -> Result<String> {
Ok(match path {
Some(p) => read_to_string(p)?,
None => read_to_string("./input/day_day_24.txt")?,
})
}
fn part_one(&self, input: &str) -> Result<Self::Output> {
todo!()
}
fn part_two(&self, input: &str) -> Result<Self::Output> {
todo!()
}
}

View file

@ -1 +1,25 @@
use std::{fs::read_to_string, path::Path};
use super::AocSolution;
use crate::utils::Result;
pub struct AocDayTwentyFiveSolution; pub struct AocDayTwentyFiveSolution;
impl AocSolution for AocDayTwentyFiveSolution {
type Output = u64;
fn get_input(&self, path: Option<&Path>) -> Result<String> {
Ok(match path {
Some(p) => read_to_string(p)?,
None => read_to_string("./input/day_day_25.txt")?,
})
}
fn part_one(&self, input: &str) -> Result<Self::Output> {
todo!()
}
fn part_two(&self, input: &str) -> Result<Self::Output> {
todo!()
}
}

View file

@ -1,21 +1,21 @@
use std::{collections::HashMap, fs::read_to_string, path::Path}; use std::{collections::HashMap, fs::read_to_string, path::Path};
use super::AocSolution; use super::AocSolution;
use crate::utils::Result; use crate::utils::{coord::Coord, Result};
const DIRS: [(i16, i16); 8] = [ const DIRS: [Coord; 8] = [
(1, 0), Coord::new(1, 0),
(1, -1), Coord::new(1, -1),
(0, -1), Coord::new(0, -1),
(-1, -1), Coord::new(-1, -1),
(-1, 0), Coord::new(-1, 0),
(-1, 1), Coord::new(-1, 1),
(0, 1), Coord::new(0, 1),
(1, 1), Coord::new(1, 1),
]; ];
struct XmasGrid { struct XmasGrid {
pub grid: HashMap<(i16, i16), char>, pub grid: HashMap<Coord, char>,
} }
impl XmasGrid { impl XmasGrid {
@ -24,22 +24,20 @@ impl XmasGrid {
grid: src grid: src
.lines() .lines()
.zip(0..) .zip(0..)
.flat_map(|(l, y)| l.chars().zip(0..).map(move |(c, x)| ((x, y), c))) .flat_map(|(l, y)| l.chars().zip(0..).map(move |(c, x)| (Coord::new(x, y), c)))
.collect(), .collect(),
} }
} }
fn find_xmas(&self, pos: (i16, i16)) -> usize { fn find_xmas(&self, pos: Coord) -> usize {
let mut tmp = 0; let mut tmp = 0;
for (dx, dy) in DIRS { for dir in DIRS {
let mut found = true; let mut found = true;
let (mut x, mut y) = pos;
for nxt in ['M', 'A', 'S'] { for nxt in ['M', 'A', 'S'] {
x += dx; let nxt_pos = pos + dir;
y += dy;
if self.grid.get(&(x, y)) != Some(&nxt) { if self.grid.get(&nxt_pos) != Some(&nxt) {
found = false; found = false;
break; break;
} }
@ -53,13 +51,13 @@ impl XmasGrid {
tmp tmp
} }
fn find_x_mas(&self, pos: (i16, i16)) -> usize { fn find_x_mas(&self, pos: Coord) -> usize {
let (x, y) = pos; let (x, y) = (pos.x, pos.y);
let tr = self.grid.get(&(x + 1, y + 1)); let tr = self.grid.get(&Coord::new(x + 1, y + 1));
let br = self.grid.get(&(x + 1, y - 1)); let br = self.grid.get(&Coord::new(x + 1, y - 1));
let bl = self.grid.get(&(x - 1, y - 1)); let bl = self.grid.get(&Coord::new(x - 1, y - 1));
let tl = self.grid.get(&(x - 1, y + 1)); let tl = self.grid.get(&Coord::new(x - 1, y + 1));
match (tr, bl, tl, br) { match (tr, bl, tl, br) {
(Some('S'), Some('M'), Some('M'), Some('S')) => 1, (Some('S'), Some('M'), Some('M'), Some('S')) => 1,

View file

@ -1 +1,25 @@
use std::{fs::read_to_string, path::Path};
use super::AocSolution;
use crate::utils::Result;
pub struct AocDaySevenSolution; pub struct AocDaySevenSolution;
impl AocSolution for AocDaySevenSolution {
type Output = u64;
fn get_input(&self, path: Option<&Path>) -> Result<String> {
Ok(match path {
Some(p) => read_to_string(p)?,
None => read_to_string("./input/day_day_7.txt")?,
})
}
fn part_one(&self, input: &str) -> Result<Self::Output> {
todo!()
}
fn part_two(&self, input: &str) -> Result<Self::Output> {
todo!()
}
}

View file

@ -1 +1,25 @@
use std::{fs::read_to_string, path::Path};
use super::AocSolution;
use crate::utils::Result;
pub struct AocDayEightSolution; pub struct AocDayEightSolution;
impl AocSolution for AocDayEightSolution {
type Output = u64;
fn get_input(&self, path: Option<&Path>) -> Result<String> {
Ok(match path {
Some(p) => read_to_string(p)?,
None => read_to_string("./input/day_day_8.txt")?,
})
}
fn part_one(&self, input: &str) -> Result<Self::Output> {
todo!()
}
fn part_two(&self, input: &str) -> Result<Self::Output> {
todo!()
}
}

View file

@ -1 +1,25 @@
use std::{fs::read_to_string, path::Path};
use super::AocSolution;
use crate::utils::Result;
pub struct AocDayNineSolution; pub struct AocDayNineSolution;
impl AocSolution for AocDayNineSolution {
type Output = u64;
fn get_input(&self, path: Option<&Path>) -> Result<String> {
Ok(match path {
Some(p) => read_to_string(p)?,
None => read_to_string("./input/day_day_9.txt")?,
})
}
fn part_one(&self, input: &str) -> Result<Self::Output> {
todo!()
}
fn part_two(&self, input: &str) -> Result<Self::Output> {
todo!()
}
}

View file

@ -9,7 +9,7 @@ pub struct Coord {
} }
impl Coord { impl Coord {
pub fn new(x: i16, y: i16) -> Self { pub const fn new(x: i16, y: i16) -> Self {
Self { x, y } Self { x, y }
} }
} }