~cdv/aoc-2019-rs

90a8ccd052a1af9c11d73ec810b7ab05fbff192a — Chris Vittal 1 year, 10 months ago 7941ace
Day25: output more like other parts
1 files changed, 11 insertions(+), 8 deletions(-)

M src/bin/day25/main.rs
M src/bin/day25/main.rs => src/bin/day25/main.rs +11 -8
@@ 64,25 64,19 @@ fn main() -> aoc2019::Result<()> {
    let mut ic = Intcode::new(prg);

    let mut pos = 0;
    let mut cmd = String::new();
    let mut out = String::new();

    loop {
        match ic.run()? {
            IntcodeStatus::Output(o) => {
                if o >= 0 && o < 128 {
                    print!("{}", o as u8 as char);
                    out.push(o as u8 as char);
                } else {
                    println!("large output: {}", o)
                }
            }
            IntcodeStatus::NeedsInput => {
                let b = COMMANDS.as_bytes()[pos];
                cmd.push(b as char);
                if b == b'\n' {
                    print!("{}", cmd);
                    cmd.clear();
                }

                ic.next_input(b as i64)?;
                pos += 1;
            }


@@ 91,5 85,14 @@ fn main() -> aoc2019::Result<()> {
        }
    }

    println!(
        "1: {:?}",
        out.split_whitespace()
            .map(|w| w.parse::<i64>())
            .filter(Result::is_ok)
            .nth(0)
            .ok_or("no result")??,
    );
    println!("2: Merr Chrismas!");
    Ok(())
}