2015 day 10

This commit is contained in:
dece 2021-11-07 20:43:52 +01:00
parent d81a9006cd
commit 4beec9475d

36
2015/src/bin/day10.rs Normal file
View file

@ -0,0 +1,36 @@
use aoc::input;
fn main() {
let mut v = input::read_chars();
// Part 1
for _ in 0..40 {
v = step(&v);
}
println!("Length after 40 steps: {}", v.len());
// Part 2
for _ in 0..10 {
v = step(&v);
}
println!("Length after 50 steps: {}", v.len());
}
fn step(s: &str) -> String {
let mut count = 1;
let mut pc = ' ';
let mut result = String::new();
for c in s.chars() {
if c == pc {
count += 1;
} else if pc != ' ' {
result.push_str(&count.to_string());
result.push(pc);
count = 1;
}
pc = c;
}
result.push_str(&count.to_string());
result.push(pc);
result
}