-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmain.rs
33 lines (30 loc) · 937 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
31
32
33
pub fn main() {
let mut cups: Vec<u8> = include_bytes!("../input.txt")
.into_iter()
.filter(|&b| b != &b'\n')
.map(|b| b - b'0')
.collect();
let highest = *cups.iter().max().unwrap();
for _ in 0..100 {
let cur = cups[0];
let removed = [cups.remove(1), cups.remove(1), cups.remove(1)];
for target in (1..cur).rev().chain((cur..=highest).rev()) {
if let Some(pos) = cups.iter().position(|&c| c == target) {
for removed in removed.iter().rev() {
cups.insert(pos + 1, *removed);
}
break;
}
}
cups.rotate_left(1);
}
let offset = cups.iter().position(|&c| c == 1).unwrap();
cups.rotate_left(offset);
println!(
"{}",
cups.iter()
.skip(1)
.map(|c| (c + b'0') as char)
.collect::<String>()
);
}