reformating day-18
This commit is contained in:
@@ -37,14 +37,14 @@ pub fn part1(input: &str) -> String {
|
|||||||
let corners = steps
|
let corners = steps
|
||||||
.iter()
|
.iter()
|
||||||
.scan(I64Vec2::splat(0), |cursor, next| {
|
.scan(I64Vec2::splat(0), |cursor, next| {
|
||||||
let dir =match next.direction {
|
let dir = match next.direction {
|
||||||
Direction::Up => I64Vec2::NEG_Y,
|
Direction::Up => I64Vec2::NEG_Y,
|
||||||
Direction::Down => I64Vec2::Y,
|
Direction::Down => I64Vec2::Y,
|
||||||
Direction::Left => I64Vec2::NEG_X,
|
Direction::Left => I64Vec2::NEG_X,
|
||||||
Direction::Right => I64Vec2::X,
|
Direction::Right => I64Vec2::X,
|
||||||
};
|
};
|
||||||
*cursor += next.count * dir;
|
*cursor += next.count * dir;
|
||||||
Some( *cursor)
|
Some(*cursor)
|
||||||
})
|
})
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
let perimeter = corners
|
let perimeter = corners
|
||||||
@@ -61,10 +61,14 @@ pub fn part1(input: &str) -> String {
|
|||||||
let dist = (*b - *a).abs();
|
let dist = (*b - *a).abs();
|
||||||
dist.x + dist.y
|
dist.x + dist.y
|
||||||
};
|
};
|
||||||
let area = (corners.iter().tuple_windows().map(|(a,b)| {
|
let area = (corners
|
||||||
a.x * b.y -a.y *b.x
|
.iter()
|
||||||
}).sum::<i64>() + perimeter
|
.tuple_windows()
|
||||||
)/2 +1;
|
.map(|(a, b)| a.x * b.y - a.y * b.x)
|
||||||
|
.sum::<i64>()
|
||||||
|
+ perimeter)
|
||||||
|
/ 2
|
||||||
|
+ 1;
|
||||||
area.to_string()
|
area.to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ pub fn part2(input: &str) -> String {
|
|||||||
Direction::Right => I64Vec2::X,
|
Direction::Right => I64Vec2::X,
|
||||||
};
|
};
|
||||||
*cursor += next.count * dir;
|
*cursor += next.count * dir;
|
||||||
Some( *cursor)
|
Some(*cursor)
|
||||||
})
|
})
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
@@ -76,7 +76,7 @@ pub fn part2(input: &str) -> String {
|
|||||||
.abs()
|
.abs()
|
||||||
+ 1;
|
+ 1;
|
||||||
|
|
||||||
(area ).to_string()
|
(area).to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_step(input: &str) -> IResult<&str, Step> {
|
fn parse_step(input: &str) -> IResult<&str, Step> {
|
||||||
|
|||||||
Reference in New Issue
Block a user