Day 13 part 1

This commit is contained in:
Wesley Moore 2019-12-14 13:55:32 +11:00
parent 5b9669e9ce
commit 94329a7996
No known key found for this signature in database
GPG key ID: BF67766C0BC2D0EE
3 changed files with 42 additions and 0 deletions

1
2019/input/day13.txt Normal file

File diff suppressed because one or more lines are too long

40
2019/src/bin/day13.rs Normal file
View file

@ -0,0 +1,40 @@
use std::{fs, io};
use advent_of_code::computer::{ComputeResult, Computer};
use advent_of_code::input;
use advent_of_code::point::Point;
use std::collections::HashMap;
use std::convert::TryFrom;
fn main() -> io::Result<()> {
let input = fs::read_to_string("input/day13.txt")?;
let program = input::read_separated_line(',', &input)?;
let mut computer = Computer::new('G', program, vec![], vec![]);
let res = computer.run(None, None);
assert_eq!(res, ComputeResult::Halted);
// Process the output
let final_state: HashMap<_, _> = computer
.output()
.chunks(3)
.map(|chunks| {
(
Point(
i32::try_from(chunks[0]).unwrap(),
i32::try_from(chunks[1]).unwrap(),
),
i32::try_from(chunks[2]).unwrap(),
)
})
.collect();
// How many block tiles are on the screen when the game exits?
let block_count = final_state
.iter()
.filter(|(_point, &tile_id)| tile_id == 2)
.count();
println!("Part 1: {}", block_count);
Ok(())
}

View file

@ -33,6 +33,7 @@ pub struct Pipe {
last: Option<i64>, last: Option<i64>,
} }
#[derive(Debug, Eq, PartialEq)]
pub enum ComputeResult { pub enum ComputeResult {
Halted, Halted,
NeedsInput, NeedsInput,