Files
advent-of-code-2015/src/day10.rs
2024-01-07 14:24:28 +01:00

53 lines
1.2 KiB
Rust

use std::collections::VecDeque;
use aoc_runner_derive::{aoc, aoc_generator};
#[aoc_generator(day10)]
fn parse(input: &str) -> Vec<char> {
input.chars().collect()
}
#[aoc(day10, part1)]
fn part1(input: &Vec<char>) -> usize {
solve(input, 40).len()
}
fn solve(input: &Vec<char>, runs: usize) -> String {
let mut saying: VecDeque<char> = input.iter().map(|c| *c).collect();
let mut next: VecDeque<char> = VecDeque::new();
for _ in 0..runs {
while let Some(current) = saying.pop_front() {
let mut count = 1;
while saying.front() == Some(&current) {
count += 1;
saying.pop_front();
}
let s = format!("{count}{current}");
for c in s.chars() {
next.push_back(c);
}
}
saying = next;
next = VecDeque::new();
}
saying.into_iter().collect()
}
#[aoc(day10, part2)]
fn part2(input: &[char]) -> String {
todo!()
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn part1_example() {
assert_eq!(solve(&parse("111221"), 1), "312211");
}
// #[test]
// fn part2_example() {
// assert_eq!(part2(&parse("<EXAMPLE>")), "<RESULT>");
// }
}