~cdv/aoc-2018-rs

375f42eae571ece78bba17a65b3ec6063cab5b3a — Christopher Vittal 2 years ago 6725a1a
rustfmt
3 files changed, 17 insertions(+), 8 deletions(-)

M src/bin/day17.rs
M src/bin/day18.rs
M src/file.rs
M src/bin/day17.rs => src/bin/day17.rs +9 -4
@@ 81,8 81,7 @@ fn fill(
        }
    }

    dir == -1 && (lfill || clay.contains(&lft))
        || dir == 1 && (rfill || clay.contains(&rgt))
    dir == -1 && (lfill || clay.contains(&lft)) || dir == 1 && (rfill || clay.contains(&rgt))
}

fn main() {


@@ 107,6 106,12 @@ fn main() {
    let mut flow = FxHashSet::default();
    let mut set = FxHashSet::default();
    fill(&mut flow, &mut set, &clay, max_y, 500, 0, 0);
    println!("  1: {}", flow.iter().filter(|p| p.1 >= min_y && p.1 <= max_y).count());
    println!("  2: {}", set.iter().filter(|p| p.1 >= min_y && p.1 <= max_y).count());
    println!(
        "  1: {}",
        flow.iter().filter(|p| p.1 >= min_y && p.1 <= max_y).count()
    );
    println!(
        "  2: {}",
        set.iter().filter(|p| p.1 >= min_y && p.1 <= max_y).count()
    );
}

M src/bin/day18.rs => src/bin/day18.rs +8 -3
@@ 13,10 13,12 @@ const YARD_SIZE: usize = 50;
fn print_matrix(m: &Matrix<u8>) -> io::Result<()> {
    let s = io::stdout();
    let mut s = s.lock();
    for _ in 0..m.columns { write!(s, "=")?; }
    for _ in 0..m.columns {
        write!(s, "=")?;
    }
    writeln!(s)?;
    for i in 0..m.rows {
        let row = &m.as_ref()[i*m.columns..(i+1)*m.columns];
        let row = &m.as_ref()[i * m.columns..(i + 1) * m.columns];
        s.write_all(row)?;
        writeln!(s)?;
    }


@@ 24,7 26,10 @@ fn print_matrix(m: &Matrix<u8>) -> io::Result<()> {
}

fn main() {
    let input: Vec<u8> = aoc::file::to_strings_iter(INPUT).map(Vec::from).flatten().collect();
    let input: Vec<u8> = aoc::file::to_strings_iter(INPUT)
        .map(Vec::from)
        .flatten()
        .collect();
    let mut yard = Matrix::from_vec(YARD_SIZE, YARD_SIZE, input);

    let mut m = FxHashMap::default();

M src/file.rs => src/file.rs +0 -1
@@ 43,7 43,6 @@ pub fn to_strings_iter<P: AsRef<Path>>(p: P) -> impl Iterator<Item = String> {
    to_lines(p).map(|r| r.expect("could not read line"))
}


pub fn to_single_parsed<F, P>(p: P) -> Vec<F>
where
    P: AsRef<Path>,