mirror of
https://github.com/wezm/advent-of-code.git
synced 2024-12-18 10:19:55 +00:00
Day 13 part 1
This commit is contained in:
parent
5b9669e9ce
commit
94329a7996
3 changed files with 42 additions and 0 deletions
1
2019/input/day13.txt
Normal file
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
40
2019/src/bin/day13.rs
Normal 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(())
|
||||
}
|
|
@ -33,6 +33,7 @@ pub struct Pipe {
|
|||
last: Option<i64>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Eq, PartialEq)]
|
||||
pub enum ComputeResult {
|
||||
Halted,
|
||||
NeedsInput,
|
||||
|
|
Loading…
Reference in a new issue