advent-of-code/2019/17/src/main.rs
2019-12-17 10:45:36 +01:00

25 lines
885 B
Rust

use grid::*;
use intcode::*;
use std::char;
use std::collections::HashMap;
fn main() {
// The main reason I use a hashmap here (instead of a 2D vector) is that my abstractions for
// ascii stuff all use maps ヽ( ゚ヮ・)ノ
let field: HashMap<Position2D, char> = IntComputer::without_params(read_input())
.get_all_outputs()
.iter()
.map(|n| char::from_u32(*n as u32).unwrap())
.collect::<String>()
.lines()
.enumerate()
.flat_map(move |(y, s)| s.chars().enumerate().map(move |(x, c)| ((x, y).into(), c)))
.collect();
let p1 = field
.keys()
.filter(|pos| field.get(&pos) == Some(&'#') && pos.neighbors().iter().all(|(_, p)| field.get(&p) == Some(&'#')))
.fold(0, |acc, pos| acc + pos.x * pos.y);
println!("Part 1: {}", p1);
// println!("{}", draw_ascii(&field, '.'));
}