Day 10 part 1.
This commit is contained in:
53
src/day10.rs
Normal file
53
src/day10.rs
Normal 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(¤t) {
|
||||
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>");
|
||||
// }
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
extern crate aoc_runner;
|
||||
|
||||
#[macro_use]
|
||||
extern crate aoc_runner_derive;
|
||||
|
||||
aoc_lib!{ year = 2015 }
|
||||
mod day10;
|
||||
|
||||
aoc_lib! { year = 2015 }
|
||||
|
||||
Reference in New Issue
Block a user