day(12): refactor ‹unfold› and test it
Signed-off-by: Matej Focko <mfocko@redhat.com>
This commit is contained in:
parent
63a41764ec
commit
dc2df6d7fb
1 changed files with 30 additions and 4 deletions
|
@ -9,7 +9,7 @@ use aoc_2023::*;
|
|||
type Output1 = usize;
|
||||
type Output2 = Output1;
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
struct Row {
|
||||
map: VecDeque<char>,
|
||||
damaged: VecDeque<usize>,
|
||||
|
@ -118,9 +118,12 @@ impl Row {
|
|||
|
||||
fn unfold(&self) -> Row {
|
||||
Row::new(
|
||||
vec![self.map.iter().collect::<String>(); 5]
|
||||
.join("?")
|
||||
.chars()
|
||||
self.map
|
||||
.iter()
|
||||
.cloned()
|
||||
.chain(['?'])
|
||||
.cycle()
|
||||
.take(5 * (self.map.len() + 1) - 1)
|
||||
.collect_vec(),
|
||||
self.damaged
|
||||
.iter()
|
||||
|
@ -166,6 +169,29 @@ test_sample!(day_12, Day12, 21, 525152);
|
|||
mod day_12_extended {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn unfold_1() {
|
||||
let row = Row::new(".#".chars().collect_vec(), vec![1]);
|
||||
assert_eq!(
|
||||
row.unfold(),
|
||||
Row::new(".#?.#?.#?.#?.#".chars().collect_vec(), vec![1, 1, 1, 1, 1])
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unfold_2() {
|
||||
let row = Row::new("???.###".chars().collect_vec(), vec![1, 1, 3]);
|
||||
assert_eq!(
|
||||
row.unfold(),
|
||||
Row::new(
|
||||
"???.###????.###????.###????.###????.###"
|
||||
.chars()
|
||||
.collect_vec(),
|
||||
vec![1, 1, 3, 1, 1, 3, 1, 1, 3, 1, 1, 3, 1, 1, 3]
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn arrangements_1() {
|
||||
let mut row = Row::new("???.###".chars().collect_vec(), vec![1, 1, 3]);
|
||||
|
|
Loading…
Reference in a new issue