From b55b0374f540251b93345655e8efe5052f83a812 Mon Sep 17 00:00:00 2001 From: Dylan Thies Date: Tue, 19 Dec 2023 10:11:27 -0500 Subject: [PATCH] reformating day-18 --- 2023/day-18/src/part1.rs | 26 +++++++++++++++----------- 2023/day-18/src/part2.rs | 14 +++++++------- 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/2023/day-18/src/part1.rs b/2023/day-18/src/part1.rs index ed05970..b93e05d 100644 --- a/2023/day-18/src/part1.rs +++ b/2023/day-18/src/part1.rs @@ -37,14 +37,14 @@ pub fn part1(input: &str) -> String { let corners = steps .iter() .scan(I64Vec2::splat(0), |cursor, next| { - let dir =match next.direction { - Direction::Up => I64Vec2::NEG_Y, - Direction::Down => I64Vec2::Y, - Direction::Left => I64Vec2::NEG_X, - Direction::Right => I64Vec2::X, - }; + let dir = match next.direction { + Direction::Up => I64Vec2::NEG_Y, + Direction::Down => I64Vec2::Y, + Direction::Left => I64Vec2::NEG_X, + Direction::Right => I64Vec2::X, + }; *cursor += next.count * dir; - Some( *cursor) + Some(*cursor) }) .collect::>(); let perimeter = corners @@ -61,10 +61,14 @@ pub fn part1(input: &str) -> String { let dist = (*b - *a).abs(); dist.x + dist.y }; - let area = (corners.iter().tuple_windows().map(|(a,b)| { - a.x * b.y -a.y *b.x - }).sum::() + perimeter - )/2 +1; + let area = (corners + .iter() + .tuple_windows() + .map(|(a, b)| a.x * b.y - a.y * b.x) + .sum::() + + perimeter) + / 2 + + 1; area.to_string() } diff --git a/2023/day-18/src/part2.rs b/2023/day-18/src/part2.rs index 0c6729d..6bed44f 100644 --- a/2023/day-18/src/part2.rs +++ b/2023/day-18/src/part2.rs @@ -41,13 +41,13 @@ pub fn part2(input: &str) -> String { .iter() .scan(I64Vec2::splat(0), |cursor, next| { let dir = match next.direction { - Direction::Up => I64Vec2::NEG_Y, - Direction::Down => I64Vec2::Y, - Direction::Left => I64Vec2::NEG_X, - Direction::Right => I64Vec2::X, - }; + Direction::Up => I64Vec2::NEG_Y, + Direction::Down => I64Vec2::Y, + Direction::Left => I64Vec2::NEG_X, + Direction::Right => I64Vec2::X, + }; *cursor += next.count * dir; - Some( *cursor) + Some(*cursor) }) .collect::>(); @@ -76,7 +76,7 @@ pub fn part2(input: &str) -> String { .abs() + 1; - (area ).to_string() + (area).to_string() } fn parse_step(input: &str) -> IResult<&str, Step> {