current approach for day 4

this does not work yet
Dieser Commit ist enthalten in:
Sebastian Tobie 2024-12-04 13:22:39 +01:00
Ursprung d430c8e15e
Commit 4f32ca95cf

78
src/bin/2024/04.rs Normale Datei
Datei anzeigen

@ -0,0 +1,78 @@
#[allow(unused_variables)]
use std::ops::RangeInclusive;
#[allow(unused_imports)]
use advent_of_code_macros::{include_data, include_example};
include_data!(DATA 2024 04);
#[derive(Debug, Clone)]
enum Direction {
Forward(usize, usize),
Backward(usize, usize),
}
impl Direction {
fn iter(&self) -> RangeInclusive<usize> {
let (from, to) = match self {
Direction::Forward(from, to) => (from, to),
Direction::Backward(to, from) => (from, to),
};
*from..=*to
}
}
fn main() {
let table: Vec<Vec<char>> = DATA
.split('\n')
.map(|line| line.chars().collect())
.collect();
let length = table[0].len();
let mut xmas;
let mut amount = 0;
let directions = [
Direction::Forward(0, length - 1),
Direction::Backward(0, length - 1),
];
for r in directions.clone() {
for c in directions.clone() {
println!("Horizontal: {:?}, vertical: {:?}", r.clone(), c.clone());
for row in r.iter() {
xmas = 0;
for column in c.iter() {
println!(
"Row {}, Column {}, dir {:?} {:?}",
row,
column,
r.clone(),
c.clone()
);
match (xmas, table[row][column]) {
(_x, 'X') => {
xmas = 1;
//println!("Found X, previous was {}", _x)
}
(1, 'M') => {
xmas = 2;
//println!("Found XM")
}
(2, 'A') => {
xmas = 3;
//println!("Found XMA")
}
(3, 'S') => {
xmas = 0;
amount += 1;
//println!("found XMAS in {}:{}", row, column);
}
(_x, _ch) => {
xmas = 0;
//println!("Reset, was {}({})", _x, _ch)
}
}
}
}
}
}
println!("There are {} XMAS in text", amount);
}