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