From e7f95fc2434f6adcfeecb3027ff8fa1ee02534b4 Mon Sep 17 00:00:00 2001 From: mat ess Date: Mon, 12 Dec 2022 01:04:48 -0500 Subject: [PATCH] Day 12 wip --- inputs/12.small.txt | 5 +++ inputs/12.txt | 41 ++++++++++++++++++++++ src/main.rs | 85 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 131 insertions(+) create mode 100644 inputs/12.small.txt create mode 100644 inputs/12.txt diff --git a/inputs/12.small.txt b/inputs/12.small.txt new file mode 100644 index 0000000..86e9cac --- /dev/null +++ b/inputs/12.small.txt @@ -0,0 +1,5 @@ +Sabqponm +abcryxxl +accszExk +acctuvwj +abdefghi diff --git a/inputs/12.txt b/inputs/12.txt new file mode 100644 index 0000000..5dab450 --- /dev/null +++ b/inputs/12.txt @@ -0,0 +1,41 @@ +abcccccccaaaaaaaaccccccccccaaaaaaccccccaccaaaaaaaccccccaacccccccccaaaaaaaaaaccccccccccccccccccccccccccccccccaaaaa +abcccccccaaaaaaaaacccccccccaaaaaacccccaaacaaaaaaaaaaaccaacccccccccccaaaaaaccccccccccccccccccccccccccccccccccaaaaa +abcccccccaaaaaaaaaaccccccccaaaaaacaaacaaaaaaaaaaaaaaaaaaccccccccccccaaaaaaccccccccccccccaaacccccccccccccccccaaaaa +abaaacccccccaaaaaaacccccccccaaacccaaaaaaaaaaaaaaaaaaaaaaaaacccccccccaaaaaaccccccccccccccaaacccccccccccccccccaaaaa +abaaaaccccccaaaccccccccccccccccccccaaaaaaaaacaaaacacaaaaaacccccccccaaaaaaaacccccccccccccaaaaccaaacccccccccccaccaa +abaaaaccccccaaccccaaccccccccccccccccaaaaaaacaaaaccccaaaaaccccccccccccccccacccccccccccccccaaaaaaaaacccccccccccccca +abaaaaccccccccccccaaaacccccccccaacaaaaaaaacccaaacccaaacaacccccccccccccccccccccccccccciiiiaaaaaaaacccccccccccccccc +abaaacccccccccccaaaaaacccccccccaaaaaaaaaaacccaaacccccccaacccccccccccaacccccccccccccciiiiiiijaaaaccccccccaaccccccc +abaaaccccccccccccaaaacccccccccaaaaaaaacaaacccaaaccccccccccccccccccccaaacaaacccccccciiiiiiiijjjacccccccccaaacccccc +abcccccaacaacccccaaaaaccccccccaaaaaacccccacaacccccccccccccccccccccccaaaaaaaccccccciiiinnnoijjjjjjjjkkkaaaaaaacccc +abcccccaaaaacccccaacaaccccccccccaaaacccaaaaaaccccccccccccccccccccccccaaaaaaccccccciiinnnnooojjjjjjjkkkkaaaaaacccc +abccccaaaaacccccccccccccccccccccaccccccaaaaaaaccccccccccccccccccccaaaaaaaaccccccchhinnnnnoooojjooopkkkkkaaaaccccc +abccccaaaaaaccccccccccccccccccccccccccccaaaaaaacccccccccccccccccccaaaaaaaaacccccchhhnnntttuooooooopppkkkaaaaccccc +abccccccaaaaccccccccccacccccccccccccccccaaaaaaacccaaccccccccccccccaaaaaaaaaaccccchhhnnttttuuoooooppppkkkaaaaccccc +abccccccaccccccccccccaaaacaaaccccccccccaaaaaacaaccaacccaaccccccccccccaaacaaacccchhhnnnttttuuuuuuuuupppkkccaaccccc +abccccccccccccccaaccccaaaaaaaccccccccccaaaaaacaaaaaacccaaaaaaccccccccaaacccccccchhhnnntttxxxuuuuuuupppkkccccccccc +abcccccccccccccaaaacccaaaaaaacccaccccccccccaaccaaaaaaacaaaaaaccccccccaacccaaccchhhhnnnttxxxxuuyyyuupppkkccccccccc +abcccccccccccccaaaaccaaaaaaaaacaaacccccccccccccaaaaaaaaaaaaaccccccccccccccaaachhhhmnnnttxxxxxxyyyuvppkkkccccccccc +abcccccccccccccaaaacaaaaaaaaaaaaaaccccccccccccaaaaaacaaaaaaaccccccccccccccaaaghhhmmmttttxxxxxyyyyvvpplllccccccccc +abccacccccccccccccccaaaaaaaaaaaaaaccccccccccccaaaaaacccaaaaaacccaacaacccaaaaagggmmmttttxxxxxyyyyvvppplllccccccccc +SbaaaccccccccccccccccccaaacaaaaaaaacccccccccccccccaacccaaccaacccaaaaacccaaaagggmmmsttxxxEzzzzyyvvvppplllccccccccc +abaaaccccccccccccccccccaaaaaaaaaaaaacaaccccccccccccccccaaccccccccaaaaaccccaagggmmmsssxxxxxyyyyyyvvvqqqlllcccccccc +abaaacccccccccccccccccccaaaaaaaaaaaaaaaaacccccccccccccccccccccccaaaaaaccccaagggmmmsssxxxwywyyyyyyvvvqqlllcccccccc +abaaaaacccccccccccccccccccaacaaaccaaaaaaacccccccccccccccccccccccaaaaccccccaagggmmmssswwwwwyyyyyyyvvvqqqllcccccccc +abaaaaaccccccccccccccccccccccaaaccccaaaacccccccccccccccccaaccaacccaaccccccccgggmmmmssssswwyywwvvvvvvqqqlllccccccc +abaaaaacccccccccccccaccacccccaaaccccaaaacccccccccccccccccaaaaaacccccccccccaaggggmllllsssswwywwwvvvvqqqqlllccccccc +abaaccccccccccccccccaaaaccccccccccccaccaccccccccccccccccccaaaaacccccccccccaaagggglllllssswwwwwrrqqqqqqmmllccccccc +abaaccccccccccccccccaaaaaccccccaaccaaccccccccccccccccccccaaaaaaccaacccccccaaaaggfffllllsswwwwrrrrqqqqqmmmcccccccc +abacaaaccccccccccccaaaaaaccccccaaaaaaccccccaacccccccccccaaaaaaaacaaacaaccccaaaaffffflllsrrwwwrrrmmmmmmmmmcccccccc +abaaaaaccccccccccccaaaaaaccccccaaaaaccccccaaaaccccccccccaaaaaaaacaaaaaaccccaaaaccfffflllrrrrrrkkmmmmmmmccccaccccc +abaaaacccccccccccccccaaccccccccaaaaaacccccaaaacccccccccccccaaccaaaaaaaccccccccccccffflllrrrrrkkkmmmmmccccccaccccc +abaaacccccccccccccccccccccccccaaaaaaaaccccaaaacccccccccccccaaccaaaaaaacccccccccccccfffllkrrrkkkkmddddcccccaaacccc +abaaacccccccccccccccccccccccccaaaaaaaacccccccccccccccccccccccccccaaaaaaccccccccccccfffllkkkkkkkdddddddcaaaaaacccc +abaaaacccccccccccccccccccccccccccaaccccccccccccccccccccccccccccccaacaaacccccccccccccfeekkkkkkkddddddcccaaaccccccc +abcaaacccccccccccaaaccccccccaacccaaccccaaaaaccccaaaccccccccccccccaaccccccccccccccccceeeeekkkkdddddccccccaaccccccc +abccccccccccccccaaaaaaccccccaaacaaccacaaaaaaaccaaaaccccccccccaccaaccccccccccccccccccceeeeeeeedddacccccccccccccccc +abccccccccccccccaaaaaacccccccaaaaacaaaaaccaaaaaaaacccccccccccaaaaacccccccccccccccccccceeeeeeedaaacccccccccccccaaa +abccccccaaacccccaaaaacccccccaaaaaacaaaaaaaaaaaaaaaccccccccccccaaaaaccccccccccccccccccccceeeeecaaacccccccccccccaaa +abccccccaaaccccccaaaaacccccaaaaaaaaccaaaaacaaaaaaccccccccccccaaaaaacccccccccccccccccccccaaaccccaccccccccccccccaaa +abccccaacaaaaacccaaaaacccccaaaaaaaacaaaaaaaaaaaaaaaccccaaaaccaaaacccccccccccccccccccccccaccccccccccccccccccaaaaaa +abccccaaaaaaaaccccccccccccccccaaccccaacaaaaaaaaaaaaaaccaaaaccccaaacccccccccccccccccccccccccccccccccccccccccaaaaaa diff --git a/src/main.rs b/src/main.rs index 5327078..a2909bb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -274,9 +274,94 @@ solutions! { let monkeys = input.split("\n\n").map(|s| Monkey::from_str(s, true)).collect(); run_rounds(monkeys, 10000).into() } + ], + [ + // day 12 part 1 + |input| { + let map = Map::from_string(input); + map.navigate().into() + }, + // day 12 part 1 + |input| { + todo!() + }, ] } +#[derive(Debug)] +struct Map { + map: Vec>, + start: (usize, usize), + end: (usize, usize), +} + +impl Map { + fn navigate(self) -> u64 { + // this is fuckin buggy + let (mut x, mut y) = self.start; + let mut last = (x, y); + let mut prior = (x, y); + let mut steps = 0; + while (x, y) != self.end { + let level = self.map[x][y]; + print!("moving from ({x},{y}) to "); + prior = last; + last = (x, y); + (x, y, _) = self + .neighbors(x, y) + .filter(|(_, _, neighbor)| (level..=level + 1).contains(neighbor)) + .filter(|(nx, ny, _)| (*nx, *ny) != prior) + .max_by_key(|(_, _, neighbor)| *neighbor) + .unwrap(); + println!("({x},{y})"); + steps += 1; + } + steps + } + + fn neighbors(&self, x: usize, y: usize) -> impl Iterator { + let mut ns = vec![]; + if x > 0 { + ns.push((x - 1, y, self.map[x - 1][y])) + } + if x < self.map.len() - 1 { + ns.push((x + 1, y, self.map[x + 1][y])) + } + if y > 0 { + ns.push((x, y - 1, self.map[x][y - 1])) + } + if y < self.map[0].len() - 1 { + ns.push((x, y + 1, self.map[x][y + 1])) + } + ns.into_iter() + } + + fn from_string(input: String) -> Self { + let mut map = vec![]; + let mut start = (0, 0); + let mut end = (0, 0); + for (row, line) in input.trim().lines().enumerate() { + let new_row = line + .chars() + .enumerate() + .map(|(col, c)| match c { + 'S' => { + start = (row, col); + 0 + } + 'E' => { + end = (row, col); + 25 + } + _ => c as isize - 'a' as isize, + }) + .collect(); + map.push(new_row); + } + Map { map, start, end } + } +} + fn run_rounds(mut monkeys: Vec, n: usize) -> u64 { let mod_factor: usize = monkeys.iter().map(|m| m.test).product(); let mut counts = vec![0; monkeys.len()];