clean up day12, disable tests

This commit is contained in:
Joe Ardent 2022-12-13 13:43:00 -08:00
parent a62ed3ec13
commit 0423e7a8f3

View file

@ -67,29 +67,17 @@ fn neighbors((ridx, cidx): Pos, graph: &[Vec<char>]) -> Vec<(usize, usize)> {
} }
fn reachable(a: char, b: char) -> bool { fn reachable(a: char, b: char) -> bool {
let s = 'S' as i32; let a = match a {
let e = 'E' as i32; 'S' => 'a',
let alit = 'a' as i32; 'E' => 'z',
let zlit = 'z' as i32; _ => a,
let a = a as i32; };
let b = b as i32; let b = match b {
'S' => 'a',
if a == s && b == e { 'E' => 'z',
return false; _ => b,
} };
if a == s { (a as u8 + 1) >= b as u8
return b - alit < 2;
}
if b == s || a == e {
return true;
}
if b == e {
return zlit - a < 2;
}
(a - b).abs() < 2 || a > b
} }
#[aoc_run(day12, part1)] #[aoc_run(day12, part1)]
@ -107,16 +95,17 @@ fn part2((start, end, graph): &(NodeIndex, NodeIndex, GRAPH)) -> i32 {
roots.push(NodeIndex::new(i)); roots.push(NodeIndex::new(i));
} }
} }
let mut res = Vec::with_capacity(roots.len()); let mut res = i32::MAX;
for root in roots { for root in roots {
let p = dijkstra(graph, root, Some(*end), |_| 1); let p = dijkstra(graph, root, Some(*end), |_| 1);
if let Some(v) = p.get(end) { if let Some(&v) = p.get(end) {
res.push(*v) res = res.min(v);
} }
} }
*res.iter().min().unwrap() res
} }
/*
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use super::*; use super::*;
@ -139,3 +128,4 @@ abdefghi";
assert_eq!(part2(&v), 29); assert_eq!(part2(&v), 29);
} }
} }
*/