Day 10 part 1.

This commit is contained in:
2024-01-07 14:24:28 +01:00
parent 483ab1a8bd
commit 2cfc050818
2 changed files with 56 additions and 2 deletions

53
src/day10.rs Normal file
View File

@@ -0,0 +1,53 @@
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>");
// }
}

View File

@@ -1,6 +1,7 @@
extern crate aoc_runner; extern crate aoc_runner;
#[macro_use] #[macro_use]
extern crate aoc_runner_derive; extern crate aoc_runner_derive;
mod day10;
aoc_lib! { year = 2015 } aoc_lib! { year = 2015 }