-
Notifications
You must be signed in to change notification settings - Fork 0
/
day7.rs
48 lines (38 loc) · 1.04 KB
/
day7.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
use std::fs;
// use std::cmp;
fn main() {
let input = fs::read_to_string("day7.input")
.expect("Something went wrong reading the file");
let mut input = input.lines().collect::<Vec<&str>>();
input.sort();
println!("{:?}", input);
let mut res: Vec<char> = Vec::new();
for l in input {
let first: char = l[5..6].parse::<char>().unwrap();
let second: char = l[36..37].parse::<char>().unwrap();
let mut index = 27;
for i in 0..res.len() {
if res[i] == first {
index = i + 1;
break;
}
}
if index == 27 {
res.push(first);
index = res.len() - 1;
}
let mut i = 0;
for i in index..res.len() {
if res[i] > second {
res.insert(i, second);
break;
} else if res[i] == second {
break;
}
}
if i == res.len() {
res.push(second);
}
}
println!("{:?}", res);
}