Skip to content

Commit

Permalink
Solve day 10
Browse files Browse the repository at this point in the history
  • Loading branch information
caass committed Sep 16, 2024
1 parent 3cd188b commit 7e07304
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 2 deletions.
37 changes: 37 additions & 0 deletions src/2015/10.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
use eyre::Result;
use itertools::Itertools;

use crate::types::{problem, Problem};

pub const ELVES_LOOK_ELVES_SAY: Problem = problem!(part1, part2);

fn part1(input: &str) -> Result<usize> {
let mut n = input.to_string();
dbg!(&n);
for _ in 0..40 {
n = look_and_say(&n);
dbg!(&n);
}

Ok(n.len())
}

fn part2(input: &str) -> Result<usize> {
let mut n = input.to_string();
for _ in 0..50 {
n = look_and_say(&n);
}

Ok(n.len())
}

fn look_and_say(n: &str) -> String {
let mut out = String::new();
for (digit, group) in &n.to_string().chars().chunk_by(|ch| *ch) {
let num_repetitions = group.count().to_string();
out.push_str(&num_repetitions);
out.push(digit);
}

out
}
5 changes: 3 additions & 2 deletions src/2015/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use phf::phf_map;
use crate::types::ProblemSet;
use crate::util::mod_days;

mod_days!(1, 2, 3, 4, 5, 6, 7, 8, 9);
mod_days!(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);

pub const PROBLEMS: ProblemSet = ProblemSet(phf_map! {
1u8 => NOT_QUITE_LISP,
Expand All @@ -14,5 +14,6 @@ pub const PROBLEMS: ProblemSet = ProblemSet(phf_map! {
6u8 => PROBABLY_A_FIRE_HAZARD,
7u8 => SOME_ASSEMBLY_REQUIRED,
8u8 => MATCHSTICKS,
9u8 => ALL_IN_A_SINGLE_NIGHT
9u8 => ALL_IN_A_SINGLE_NIGHT,
10u8 => ELVES_LOOK_ELVES_SAY
});
12 changes: 12 additions & 0 deletions tests/2015.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,15 @@ mod day9 {
crate::util::aoc!(2015/9-2: 898);
}
}

mod day10 {
#[test]
fn part1() {
crate::util::aoc!(2015/10-1: 360154);
}

#[test]
fn part2() {
crate::util::aoc!(2015/10-2: 5103798);
}
}

0 comments on commit 7e07304

Please sign in to comment.