-
Notifications
You must be signed in to change notification settings - Fork 0
/
10.rs
40 lines (32 loc) · 938 Bytes
/
10.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
const INPUT: &str = "1321131112";
fn main() { one(); two(); }
fn one() {
let mut result: Vec<u8> = INPUT.chars().map(|s| s.to_digit(10).unwrap() as u8).collect();
for _ in 0..40 { result = look_and_say(&result); }
result = result.len();
println!("{result}");
}
fn look_and_say(input: &Vec<u8>) -> Vec<u8> {
let mut result = vec![];
let mut occurences = 0;
let mut current = input[0];
for n in input {
if current != *n {
result.push(occurences);
result.push(current);
occurences = 1;
current = *n;
} else {
occurences += 1;
}
}
result.push(occurences);
result.push(current);
result
}
fn two() {
let mut input: Vec<u8> = INPUT.chars().map(|s| s.to_digit(10).unwrap() as u8).collect();
for _ in 0..50 { input = look_and_say(&input); }
let result = input.len();
println!("{result}");
}