-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.rs
70 lines (67 loc) · 3.24 KB
/
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
use rayon::prelude::*;
const INPUT: &str = include_str!("input.txt");
fn main() {
let sum = INPUT
.par_lines()
.map(|line| {
let (a, b) = rayon::join(
|| {
let mut i = 0;
loop {
let line = &line[i..];
match line {
_ if line.starts_with('1') => return 1,
_ if line.starts_with('2') => return 2,
_ if line.starts_with('3') => return 3,
_ if line.starts_with('4') => return 4,
_ if line.starts_with('5') => return 5,
_ if line.starts_with('6') => return 6,
_ if line.starts_with('7') => return 7,
_ if line.starts_with('8') => return 8,
_ if line.starts_with('9') => return 9,
_ if line.starts_with("one") => return 1,
_ if line.starts_with("two") => return 2,
_ if line.starts_with("six") => return 6,
_ if line.starts_with("four") => return 4,
_ if line.starts_with("five") => return 5,
_ if line.starts_with("nine") => return 9,
_ if line.starts_with("three") => return 3,
_ if line.starts_with("seven") => return 7,
_ if line.starts_with("eight") => return 8,
_ => i += 1,
};
}
},
|| {
let mut i = 0;
loop {
let line = &line[..(line.len() - i)];
match line {
_ if line.ends_with('1') => return 1,
_ if line.ends_with('2') => return 2,
_ if line.ends_with('3') => return 3,
_ if line.ends_with('4') => return 4,
_ if line.ends_with('5') => return 5,
_ if line.ends_with('6') => return 6,
_ if line.ends_with('7') => return 7,
_ if line.ends_with('8') => return 8,
_ if line.ends_with('9') => return 9,
_ if line.ends_with("one") => return 1,
_ if line.ends_with("two") => return 2,
_ if line.ends_with("six") => return 6,
_ if line.ends_with("four") => return 4,
_ if line.ends_with("five") => return 5,
_ if line.ends_with("nine") => return 9,
_ if line.ends_with("three") => return 3,
_ if line.ends_with("seven") => return 7,
_ if line.ends_with("eight") => return 8,
_ => i += 1,
};
}
},
);
a * 10 + b
})
.sum::<u16>();
println!("{sum}");
}