Part 2 for 2021 day 4

[?]
Dec 8, 2021, 3:19 AM
J5J4TGTH2BFRP3IUTKMYETEKTZKDTCQU2IPRHVUPUCQ6BEAEBIQQC

Dependencies

  • [2] P7M5N7HR Part 1 solution for 2021 day 4

Change contents

  • replacement in 2021/day4.rs at line 48
    [2.1296][2.1296:1388]()
    fn parse_boards<I: Iterator<Item = S>, S: AsRef<str>>(input: &mut I) -> Vec<Vec<Vec<u8>>> {
    [2.1296]
    [2.1388]
    fn parse_boards<'a, I: Iterator<Item = S>, S: AsRef<str>>(input: &'a mut I) -> impl Iterator<Item=Vec<Vec<u8>>> + 'a {
  • edit in 2021/day4.rs at line 63
    [2.1783][2.1783:1802]()
    .collect()
  • replacement in 2021/day4.rs at line 76
    [2.2204][2.2204:2305]()
    let boards = parse_boards(&mut lines.flat_map(Result::ok));
    let (score,step) = boards.iter()
    [2.2204]
    [2.2305]
    let mut lines = lines.flat_map(Result::ok);
    let boards = parse_boards(&mut lines);
    let (score1,step1,score2,step2) = boards
  • replacement in 2021/day4.rs at line 83
    [2.2508][2.2508:2729]()
    .min_by(|(_,a),(_,b)| a.cmp(b))
    .unwrap();
    println!("Time: {}", step);
    println!("Score: {}", score);
    let (last_called,_) = draws.iter()
    .filter(|(_,w)| *w == &step)
    .next()
    [2.2508]
    [2.2729]
    .fold(None, |acc, (score,step)| match acc {
    None => Some((score,step,score,step)),
    Some((score1,step1,score2,step2)) => {
    let (score1,step1) = if step < step1 {
    (score,step)
    } else {
    (score1,step1)
    };
    let (score2,step2) = if step > step2 {
    (score,step)
    } else {
    (score2,step2)
    };
    Some((score1,step1,score2,step2))
    }
    })
  • edit in 2021/day4.rs at line 100
    [2.2748]
    [2.2748]
    println!("- Part 1 -");
    println!("Time: {}", step1);
    println!("Score: {}", score1);
    let (last_called,_) = draws.iter().filter(|(_,step)| **step == step1).next().unwrap();
  • replacement in 2021/day4.rs at line 105
    [2.2794][2.2794:2872]()
    println!("Product: {}", score * <u8 as Into<usize>>::into(*last_called));
    [2.2794]
    [2.2872]
    println!("Product: {}", score1 * *last_called as usize);
    println!();
    println!("- Part 2 -");
    println!("Time: {}", step2);
    println!("Score: {}", score2);
    let (last_called,_) = draws.iter().filter(|(_,step)| **step == step2).next().unwrap();
    println!("Last called: {}", last_called);
    println!("Product: {}", score2 * *last_called as usize);