mirror of
https://github.com/LeMoonStar/AoC24.git
synced 2025-07-08 00:10:00 +02:00
🎨 Day 4: Formatting
This commit is contained in:
parent
11b61a2527
commit
bb4c059b25
1 changed files with 7 additions and 14 deletions
|
@ -4,7 +4,7 @@ use super::{Answer, Day, DayImpl};
|
||||||
|
|
||||||
const CURRENT_DAY: u8 = 4;
|
const CURRENT_DAY: u8 = 4;
|
||||||
|
|
||||||
#[derive(Debug, Clone,Copy)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
enum Direction {
|
enum Direction {
|
||||||
East,
|
East,
|
||||||
West,
|
West,
|
||||||
|
@ -13,11 +13,11 @@ enum Direction {
|
||||||
NorthEast,
|
NorthEast,
|
||||||
NorthWest,
|
NorthWest,
|
||||||
SouthEast,
|
SouthEast,
|
||||||
SouthWest
|
SouthWest,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct LetterWall (Vec<Vec<char>>);
|
pub struct LetterWall(Vec<Vec<char>>);
|
||||||
|
|
||||||
impl LetterWall {
|
impl LetterWall {
|
||||||
fn at(&self, x: usize, y: usize) -> Option<&char> {
|
fn at(&self, x: usize, y: usize) -> Option<&char> {
|
||||||
|
@ -31,6 +31,7 @@ impl LetterWall {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_upper_left_of_xmas(&self, x: usize, y: usize) -> Option<Direction> {
|
fn is_upper_left_of_xmas(&self, x: usize, y: usize) -> Option<Direction> {
|
||||||
|
#[rustfmt::skip]
|
||||||
match(
|
match(
|
||||||
self.at( x, y), self.at( x+1, y), self.at( x+2, y), self.at( x+3, y),
|
self.at( x, y), self.at( x+1, y), self.at( x+2, y), self.at( x+3, y),
|
||||||
self.at( x, y+1), self.at( x+1, y+1), self.at( x+2, y+1), self.at( x+3, y+1),
|
self.at( x, y+1), self.at( x+1, y+1), self.at( x+2, y+1), self.at( x+3, y+1),
|
||||||
|
@ -91,7 +92,7 @@ impl LetterWall {
|
||||||
|
|
||||||
pub fn count_xmas(&self) -> u64 {
|
pub fn count_xmas(&self) -> u64 {
|
||||||
let mut count = 0;
|
let mut count = 0;
|
||||||
for y in 0..self.0.len(){
|
for y in 0..self.0.len() {
|
||||||
for x in 0..self.0[0].len() {
|
for x in 0..self.0[0].len() {
|
||||||
if let Some(_dir) = self.is_upper_left_of_xmas(x, y) {
|
if let Some(_dir) = self.is_upper_left_of_xmas(x, y) {
|
||||||
dprintln!("FOUND AT {} {} '{}' - DIR: {:?}", x, y, self.0[y][x], _dir);
|
dprintln!("FOUND AT {} {} '{}' - DIR: {:?}", x, y, self.0[y][x], _dir);
|
||||||
|
@ -105,12 +106,7 @@ impl LetterWall {
|
||||||
|
|
||||||
impl From<&str> for LetterWall {
|
impl From<&str> for LetterWall {
|
||||||
fn from(value: &str) -> Self {
|
fn from(value: &str) -> Self {
|
||||||
Self (
|
Self(value.lines().map(|v| v.chars().collect()).collect())
|
||||||
value
|
|
||||||
.lines()
|
|
||||||
.map(|v| v.chars().collect())
|
|
||||||
.collect()
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -126,10 +122,7 @@ impl DayImpl<Data> for Day<CURRENT_DAY> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn init(input: &str) -> (Self, Data) {
|
fn init(input: &str) -> (Self, Data) {
|
||||||
(
|
(Self {}, input.into())
|
||||||
Self {},
|
|
||||||
input.into(),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn one(&self, data: &mut Data) -> Answer {
|
fn one(&self, data: &mut Data) -> Answer {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue