-
Notifications
You must be signed in to change notification settings - Fork 0
/
10.rs
41 lines (33 loc) · 996 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
41
const INPUT: &str = include_str!("10.txt");
fn main() { one(); two(); }
fn one() {
// TODO FALSE
let mut input_vec: Vec<u8> = INPUT.chars().map(|s| s.to_digit(10).unwrap() as u8).collect();
for _ in 0..40 { input_vec = look_and_say(&input_vec); }
let result = input_vec.len();
print!("10.1: {result}\t\t");
}
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!("10.2: {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
}