~cdv/aoc-2019-rs

c11aef2ae0aa713466a83fa3128cb7b55683302b — Chris Vittal 3 months ago 2480c05 master
Day 24: Use cycle finding for part 1
1 files changed, 22 insertions(+), 8 deletions(-)

M src/bin/day24/main.rs
M src/bin/day24/main.rs => src/bin/day24/main.rs +22 -8
@@ 21,7 21,7 @@ impl Eris {
        Ok(grid)
    }

    fn step(&mut self) {
    fn step(self) -> Self {
        let mut new = 0;

        for r in 0..S {


@@ 35,7 35,7 @@ impl Eris {
            }
        }

        self.0 = new
        Eris(new)
    }

    fn adj(&self, r: usize, c: usize) -> u32 {


@@ 121,15 121,29 @@ fn step(bugs: HashSet<(i16, i8, i8)>) -> HashSet<(i16, i8, i8)> {
    nbugs
}

fn find_first_repeat(start: Eris) -> Eris {
    let mut tort = start.step();
    let mut hare = start.step().step();

    while tort != hare {
        tort = tort.step();
        hare = hare.step().step();
    }

    tort = start;
    while tort != hare {
        tort = tort.step();
        hare = hare.step();
    }

    tort
}

fn main() -> aoc2019::Result<()> {
    let s = aoc2019::chomp_to_str()?;
    let mut e = Eris::build(&s)?;
    let mut m = HashSet::new();
    let e = Eris::build(&s)?;

    while m.insert(e) {
        e.step();
    }
    println!("1: {}", e.rating());
    println!("1: {}", find_first_repeat(e).rating());

    let mut bugs = HashSet::<(i16, i8, i8)>::new();
    for (r, l) in s.lines().enumerate() {