day19 format
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
use std::collections::HashMap;
|
||||
use super::day05::{IntCodeComputer, RAM};
|
||||
use itertools::Itertools;
|
||||
use std::collections::HashMap;
|
||||
|
||||
pub fn run() {
|
||||
let program = super::day05::load_ram("input/day19.txt");
|
||||
@@ -12,9 +12,7 @@ fn part1(program: &RAM, max_perimeter: i128) {
|
||||
let result = (0..max_perimeter)
|
||||
.flat_map(|x| {
|
||||
(0..max_perimeter)
|
||||
.map(|y| {
|
||||
read_coordinate(program, x, y)
|
||||
})
|
||||
.map(|y| read_coordinate(program, x, y))
|
||||
.collect_vec()
|
||||
})
|
||||
.filter(|v| *v)
|
||||
@@ -27,13 +25,11 @@ const SHIP_SIZE: i128 = 100;
|
||||
|
||||
fn part2(program: &RAM) {
|
||||
let mut map: HashMap<(i128, i128), bool> = HashMap::new();
|
||||
(0..SHIP_SIZE)
|
||||
.for_each(|x| {
|
||||
(0..SHIP_SIZE)
|
||||
.for_each(|y| {
|
||||
map.insert((x, y), read_coordinate(program, x, y));
|
||||
})
|
||||
});
|
||||
(0..SHIP_SIZE).for_each(|x| {
|
||||
(0..SHIP_SIZE).for_each(|y| {
|
||||
map.insert((x, y), read_coordinate(program, x, y));
|
||||
})
|
||||
});
|
||||
for perimeter in 0.. {
|
||||
extend_horizon(program, &mut map, perimeter);
|
||||
if let Some((x, y)) = check_all_squares_starting_at(&map, perimeter) {
|
||||
@@ -44,7 +40,10 @@ fn part2(program: &RAM) {
|
||||
}
|
||||
}
|
||||
|
||||
fn check_all_squares_starting_at(map: &HashMap<(i128, i128), bool>, perimeter: i128) -> Option<(i128, i128)> {
|
||||
fn check_all_squares_starting_at(
|
||||
map: &HashMap<(i128, i128), bool>,
|
||||
perimeter: i128,
|
||||
) -> Option<(i128, i128)> {
|
||||
for i in 0..=perimeter {
|
||||
if let Some(point) = check_fits(map, i, perimeter) {
|
||||
return Some(point);
|
||||
|
||||
Reference in New Issue
Block a user