From eeda13a0d67fbcdd2619504a9aa1679330a58f46 Mon Sep 17 00:00:00 2001 From: Johannes Date: Sun, 2 Oct 2022 11:06:40 +0200 Subject: [PATCH] day19 format --- src/tasks/day19.rs | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/src/tasks/day19.rs b/src/tasks/day19.rs index 26d741f..d4bf301 100644 --- a/src/tasks/day19.rs +++ b/src/tasks/day19.rs @@ -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); @@ -79,4 +78,4 @@ fn read_coordinate(program: &RAM, x: i128, y: i128) -> bool { let mut computer = IntCodeComputer::new(vec![x, y], program.clone()); computer.run_until_end(); *computer.get_output().first().unwrap() == 1 -} \ No newline at end of file +}