Adds Days 4 and 5.1

This commit is contained in:
Dennis Brentjes 2024-12-08 13:59:34 +01:00
parent 33d96510d3
commit e6c4b4ea7c
10 changed files with 1791 additions and 28 deletions

1
Cargo.lock generated
View File

@ -8,6 +8,7 @@ version = "0.1.0"
dependencies = [
"darling",
"quote",
"regex",
"syn",
]

View File

@ -10,4 +10,4 @@ proc-macro = true
syn = "2.0"
quote = "1.0"
darling = "0.20"
regex = "1.11"

View File

@ -3,7 +3,8 @@ extern crate proc_macro;
use proc_macro::{TokenStream, TokenTree};
use quote::quote;
use syn::{parse_macro_input, parse_quote, Expr, ItemStruct};
use regex::Regex;
use syn::{parse_macro_input, Expr, Ident, ItemStruct};
#[proc_macro_attribute]
pub fn advent_day(attrs: TokenStream, item: TokenStream, ) -> TokenStream {
@ -18,22 +19,50 @@ pub fn advent_day(attrs: TokenStream, item: TokenStream, ) -> TokenStream {
}
}
let call1 = format!("{}::new()", parts[0]);
let call2 = format!("{}::new()", parts[1]);
let part1: Expr = parse_quote!(#call1);
let part2: Expr = parse_quote!(#call2);
println!("{:?} {:?}", part1, part2);
let call1 = format!("{}::new()", &parts[0]);
let call2 = format!("{}::new()", &parts[1]);
let part1: Expr = syn::parse_str(&call1.as_str()).unwrap();
let part2: Expr = syn::parse_str(&call2.as_str()).unwrap();
let ident_part1: Ident = syn::parse_str(&parts[0].as_str()).unwrap();
let ident_part2: Ident = syn::parse_str(&parts[1].as_str()).unwrap();
let re = Regex::new(r"(\d+)").unwrap();
let hay = input.ident.to_string();
let (_, [day_nr]) = re.captures(hay.as_str()).unwrap().extract();
let input_str = format!("resources/input{}.txt", day_nr);
let output = quote! {
impl AdventDayPart1 for #ident_part1 {
fn read_input(&mut self) -> Result<(), AdventError> {
read_input_part1(self, Path::new(#input_str))
}
fn solve(&mut self) -> Result<u64, AdventError> {
solve_part1(self)
}
}
impl AdventDayPart2 for #ident_part2 {
fn read_input(&mut self) -> Result<(), AdventError> {
read_input_part2(self, Path::new(#input_str))
}
fn solve(&mut self) -> Result<u64, AdventError> {
solve_part2(self)
}
}
pub struct #ident {
part1: Box::<dyn AdventDayPart1>,
part2: Box::<dyn AdventDayPart2>
}
impl Day4 {
impl #ident {
pub fn new() -> Self {
Day4 {
Self {
part1: Box::new(#part1),
part2: Box::new(#part2)
}

140
resources/input4.txt Normal file
View File

@ -0,0 +1,140 @@
MSMMXMMAMXMAMSAMXMXXMMASAXAXAMXSXMASMXASXAXXMASMSXSAMXSMXMMXMMSMMSSSMSSSSSMMASXMAXXMASAMXMSXAXSAMXSXAMXSAMMMXMSMXSXMAMASMSAMXMSXMXSXMASXMAMX
ASAMXXAMAMXXMAMSMSMAXSAAMXMSMMAMXXMAXAXMXMMAXSMAXMMXMASAASXMXAAAXAAMAAAXAAXMASMMSAMXASAMSAMXXAXAXASMMAAAAXMMAMAAAXASAMMAMXSAMXSASASASASMSMMM
MXAMXXXMAAAMXSSXAASMMMMXSAAAAMSMXMXAMXMMSASMMMMMMXXAAAMSMMAXMMSSMMSMMMSMSSMMXMMAMXMMAXAMMAMMSMSMMXSASMMMXMASASMMMSMSASAAXAXXMAMAMMSAMXXAAXXX
XSXMMAXSXSXSAMXMSMSMAXMASMSMSMMAAAMXSAAXMAMXAAAAMMMMSMMAXXSMSXAAXAMXSAMMAAAXMSMXMAXXAXSMSSMAAAAAMASXMASMXMXSMXXAAMMSAMMSMMXMAMMAMXMMMSMSMSSS
MAMAXXXMAMMMMSAMXAXMSMMMSMXXMASMMSXASMSMMSASXXSASAXXAAXMSSMAMMXMMMMAMASMMSMMAAAMSMSMSMXAMXMSSSSSMASAMAMMXMASXSSMMSAMXMAXASXSAMMSMAXMAMXAAAAM
XASMMAMMAMXAASASMMMMAAAXXMXAMAMAXXMMSXMAAXMASAXASASMSSMXMASAXAMMAXMAMMMXMAASMMMMAXMAXAXMXMAAAAAXMXSMMSXMAMXSAAXXAMASXMASAMAMMSAAXMSMASXMMMSM
SAMAMMXSASMMMSXMAXSSSXMSMXMAMSMMMSAMXAMMMSMSM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M
XMAMXMAXXMASXSMSXMASAMXXSSMSXSSMSMSMMMXMAMMMSMAMSSMMXSXMAAAMAXXSMAXXXMXSXMAMXAMXSAMSAMXXXMAMXSMMSXXXMAMASMSMMMMMSMSASXAMAMAXSSSMXMASMSXXMAXA
MMXMSSMSXSXMAXMMXMASMMSAAAASAMXAAAAXXXMMSMASASAMXAASASMSMSXSMSAMMMAMMMAMAMASXMMMSAMMXSMSSMASAMXSXASXMSMMMAXAXMXAXAAASMSMSMXXAAAMSMSMAMMMSXMS
XSAMXMAAMSAMXMAAXMASAASMXMMMSMMSMSMSAASAASXMMXMASMMMASAAAXAAAMAMAXAAAMASXMASXAAXSAMXAAXMASASASXAMMMAAAXSMASXSAMXSMMAMAAAXAMSMSMMASAMXMAAAASM
SSMSAMXMASXMSSXMXSAMMMSXAXAXXXMAXXAXXSMSXSXXXXMASXSMXMMMSMMMXMASXSMSSSMSMMSSXSMMSAMMMSMSXMXSMMMXXXSMMMSXSMXXMXMMMXXAMSMSMXMXXXMSSSXSSSMMSSMA

1362
resources/input5.txt Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,47 +1,176 @@
use std::path::Path;
use crate::input::read_into_vec;
use super::*;
use advent_derive::advent_day;
use regex::Regex;
struct Day4Part1 {
text: Vec<String>
}
impl Day4Part1 {
fn new() -> Self {
Day4Part1{}
Day4Part1{
text: vec![]
}
}
}
struct Day4Part2 {
text: Vec<String>,
grid_size: usize
}
impl Day4Part2 {
fn new() -> Self {
Day4Part2{}
Day4Part2{
text: vec![],
grid_size: 0usize
}
}
}
impl AdventDayPart1 for Day4Part1 {
fn read_input(&mut self) -> Result<(),AdventError> {
todo!()
}
fn solve(&mut self) -> Result<u64, AdventError> {
todo!()
}
fn read_input_part1(part1: &mut Day4Part1, path: &Path) -> Result<(), AdventError> {
part1.text = read_into_vec(path)?;
Ok(())
}
impl AdventDayPart2 for Day4Part2 {
fn read_input(&mut self) -> Result<(),AdventError> {
todo!()
fn solve_part1(part1: &mut Day4Part1) -> Result<u64, AdventError> {
let lr = part1.text.clone();
let mut ud = vec![];
let grid_size = part1.text.len();
for i in 0usize .. grid_size {
ud.push(part1.text.iter().map(|s| {
s.chars().nth(i).unwrap()
}).collect::<String>());
}
fn solve(&mut self) -> Result<u64, AdventError> {
todo!()
let mut lurd = vec![];
for i in 0usize .. grid_size {
let mut j = i;
lurd.push(part1.text.iter().map(|s| {
let c;
if j >= grid_size {
c = ' ';
} else {
c = s.chars().nth(j).unwrap();
}
j += 1;
c
}).collect::<String>());
}
for i in 1usize .. grid_size {
let mut j = i;
lurd.push(ud.iter().map(|s| {
let c;
if j >= grid_size {
c = ' ';
} else {
c = s.chars().nth(j).unwrap();
}
j += 1;
c
}).collect::<String>());
}
let mut ruld = vec![];
for i in 0usize .. grid_size {
let mut j = i;
ruld.push(lr.iter().map(|s| {
let c;
if j >= grid_size {
c = ' ';
} else {
c = s.chars().rev().nth(j).unwrap();
}
j += 1;
c
}).collect::<String>());
}
for i in 1usize .. grid_size {
let mut j = 0;
ruld.push(lr.iter().skip(i).map(|s| {
let c;
if j >= grid_size {
c = ' ';
} else {
c = s.chars().rev().nth(j).unwrap();
}
j += 1;
c
}).collect::<String>());
}
let xmas_r = Regex::new("XMAS")?;
let samx_r = Regex::new("SAMX")?;
// println!("input:\n{:?}", part1.text);
// println!("lr:\n{:?}", lr);
// println!("up:\n{:?}", ud);
// println!("lurd:\n{:?}", lurd);
// println!("ruld:\n{:?}", ruld);
Ok(
lr.iter().chain(ud.iter()).chain(lurd.iter()).chain(ruld.iter()).fold(Ok(0), |sum, s| -> Result<u64, AdventError> {
let mut sum = sum?;
sum += xmas_r.find_iter(s.as_str()).count() as u64;
sum += samx_r.find_iter(s.as_str()).count() as u64;
Ok(sum)
})?
)
}
fn read_input_part2(part2: &mut Day4Part2, path: &Path) -> Result<(), AdventError> {
part2.text = read_into_vec(path)?;
part2.grid_size = part2.text.len();
Ok(())
}
fn is_m(part2: &mut Day4Part2, (x, y): (usize, usize)) -> bool {
part2.text.iter().skip(y).next().unwrap().chars().nth(x).unwrap() == 'M'
}
fn is_s(part2: &mut Day4Part2, (x, y): (usize, usize)) -> bool {
part2.text.iter().skip(y).next().unwrap().chars().nth(x).unwrap() == 'S'
}
fn is_xmas(part2: &mut Day4Part2, (x, y): (usize, usize)) -> bool {
if x == 0 || x == part2.grid_size - 1 || y == 0 || y == part2.grid_size - 1 {
return false;
}
let lr_mas = is_m(part2, (x-1, y-1)) && is_s(part2, (x+1, y+1)) || is_m(part2, (x+1, y+1)) && is_s(part2, (x-1, y-1));
let rl_mas = is_m(part2, (x+1, y-1)) && is_s(part2, (x-1, y+1)) || is_m(part2, (x-1, y+1)) && is_s(part2, (x+1, y-1));
lr_mas && rl_mas
}
fn solve_part2(part2: &mut Day4Part2) -> Result<u64, AdventError> {
let text = part2.text.clone();
Ok(
text.iter().enumerate().fold(0, |acc, (y, s)| {
acc + s.chars().enumerate().fold(0, |acc, (x, c)| {
if c == 'A' && is_xmas(part2, (x, y)) {
acc + 1
} else {
acc
}
})
})
)
}
#[advent_day(Day4Part1, Day4Part2)]
struct Day4;

93
src/days/day5.rs Normal file
View File

@ -0,0 +1,93 @@
use std::path::Path;
use advent_derive::advent_day;
use itertools::Itertools;
use regex::Regex;
use crate::input::get_lines;
use super::*;
#[derive(Debug)]
struct Order {
left: u32,
right: u32,
}
struct Day5Part1 {
ordering: Vec<Order>,
queues: Vec<Vec<u32>>
}
impl Day5Part1 {
fn new() -> Self {
Self {
ordering: vec![],
queues: vec![vec![]]
}
}
}
struct Day5Part2 {}
impl Day5Part2 {
fn new() -> Self {
Self{}
}
}
fn read_input_part1(part1: &mut Day5Part1, path: &Path) -> Result<(), AdventError> {
let mut lines = get_lines(path);
let order_regex = Regex::new(r"(\d+)\|(\d+)").unwrap();
part1.ordering = lines.by_ref().take_while(|s| {
s.as_ref().unwrap().trim() != ""
}).map(|s| -> Order {
let s = s.as_ref().unwrap().as_str();
let (_, [l, r]) = order_regex.captures(s).unwrap().extract();
Order {
left: l.parse::<u32>().unwrap(),
right: r.parse::<u32>().unwrap()
}
}).collect::<Vec<Order>>();
part1.queues = lines.map(|s| {
let s = s.as_ref().unwrap();
let print_item_regex = Regex::new(r"\d+").unwrap();
print_item_regex.find_iter(s.as_str()).map(|m| {
m.as_str().parse::<u32>().unwrap()
}).collect::<Vec<u32>>()
}).collect::<Vec<Vec<u32>>>();
Ok(())
}
fn is_correct(part1: &mut Day5Part1, q: Vec<u32>) -> bool {
q.iter().enumerate().all(|(index, item)| {
part1.ordering.iter().filter(|order| {
order.left == *item
}).all(|order| {
index < q.iter().find_position(|x| { **x == order.right } ).or(Some((usize::MAX, &0))).unwrap().0
})
})
}
fn solve_part1(part1: &mut Day5Part1) -> Result<u64, AdventError> {
Ok(part1.queues.clone().into_iter().filter(
|q| {
is_correct(part1, q.clone())
}
).fold(0u64, | acc, item| {
acc + item[item.len() / 2] as u64
}))
}
fn read_input_part2(part2: &mut Day5Part2, path: &Path) -> Result<(), AdventError> {
Ok(())
}
fn solve_part2(part2: &mut Day5Part2) -> Result<u64, AdventError> {
Ok(0)
}
#[advent_day(Day5Part1, Day5Part2)]
struct Day5;

View File

@ -18,4 +18,5 @@ pub trait AdventDay {
pub mod day1;
pub mod day2;
pub mod day3;
pub mod day4;
pub mod day4;
pub mod day5;

View File

@ -25,4 +25,10 @@ impl From<TryFromIntError> for AdventError {
fn from(e: TryFromIntError) -> Self {
AdventError(e.to_string())
}
}
impl From<regex::Error> for AdventError {
fn from(e: regex::Error) -> Self {
AdventError(e.to_string())
}
}

View File

@ -8,6 +8,7 @@ use day1::Day1;
use day2::Day2;
use day3::Day3;
use day4::Day4;
use day5::Day5;
use crate::error::AdventError;
use crate::days::*;
@ -19,6 +20,7 @@ fn main() -> Result<(), AdventError> {
Box::new(Day2::new()),
Box::new(Day3::new()),
Box::new(Day4::new()),
Box::new(Day5::new())
);
if env::args().len() == 1 {