-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.rs
30 lines (28 loc) · 954 Bytes
/
main.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
pub fn main() {
let input = include_bytes!("../input.txt");
let split = input.iter().position(|&c| c == b'\n').unwrap();
let mut map = [0u32; 0b11001_11001_11001 + 1];
let enc = |n: &[u8]| {
((n[0] - b'A') as u32) << 10 | ((n[1] - b'A') as u32) << 5 | (n[2] - b'A') as u32
};
input[split + 2..].split(|&c| c == b'\n').for_each(|node| {
map[enc(&node[0..3]) as usize] = enc(&node[7..10]) | enc(&node[12..15]) << 16;
});
println!(
"{}",
input[0..split]
.iter()
.cycle()
.scan(enc(b"AAA"), |node, step| {
*node = if step == &b'L' {
map[*node as usize] & u16::MAX as u32
} else {
map[*node as usize] >> 16
};
Some(*node & 0b11111 == (b'Z' - b'A') as u32)
})
.position(|node| node)
.unwrap()
+ 1
);
}