-
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathmain.rs
More file actions
24 lines (22 loc) · 561 Bytes
/
main.rs
File metadata and controls
24 lines (22 loc) · 561 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
pub fn main() {
let mut nums = include_str!("../input.txt")
.trim_end()
.split(',')
.map(|n| n.parse().unwrap())
.collect::<Vec<usize>>();
nums.reserve(2020);
while nums.len() < 2020 {
let last = nums.last().unwrap();
match nums
.iter()
.rev()
.enumerate()
.skip(1)
.find(|(_, n)| n == &last)
{
Some((i, _)) => nums.push(i),
None => nums.push(0),
}
}
println!("{}", nums.last().unwrap());
}