-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.rs
37 lines (34 loc) · 1.03 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
fn main() {
let entries = include_str!("../in.txt")
.split('\n')
.map(|s| s.parse::<usize>().unwrap())
.collect::<Vec<usize>>();
let count = entries.len();
println!("Part 1");
'loop1: for i in 0..(count) {
for j in 0..(count) {
let x = entries[i];
let y = entries[j];
if x != y && x + y == 2020 {
println!("{} + {} = {}", x, y, x + y);
println!("{} * {} = {}", x, y, x * y);
break 'loop1;
}
}
}
println!("Part 2:");
'loop2: for i in 0..(count) {
for j in 0..(count) {
for k in 0..(count) {
let x = entries[i];
let y = entries[j];
let z = entries[k];
if x + y + z == 2020 {
println!("{} + {} + {} = {}", x, y, z, x + y + z);
println!("{} * {} * {} = {}", x, y, z, x * y * z);
break 'loop2;
}
}
}
}
}