-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday10.rs
More file actions
33 lines (26 loc) · 750 Bytes
/
Copy pathday10.rs
File metadata and controls
33 lines (26 loc) · 750 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
25
26
27
28
29
30
31
32
33
//! Elves Look, Elves Say
//!
//! Summary:
use itertools::Itertools;
pub fn parse(input: &str) -> &str {
input.trim()
}
pub fn part1(input: &str) -> usize {
solve(input, 40)
}
pub fn part2(input: &str) -> usize {
solve(input, 50)
}
fn solve(input: &str, repetitions: u8) -> usize {
let mut process_string: String = String::from(input);
for _ in 0..repetitions {
let mut next_string: String = String::new();
for (digit, group) in &process_string.chars().chunk_by(|c| *c) {
let num: Vec<_> = group.collect();
next_string.push_str(&num.len().to_string());
next_string.push(digit);
}
process_string = next_string;
}
process_string.to_string().len()
}