generated from janezicmatej/aoc-template
solution: day 13 clean
This commit is contained in:
parent
000002707d
commit
00000280ae
|
@ -1,6 +1,5 @@
|
||||||
fn mirror_h(shape: &Vec<Vec<char>>, smudges: usize) -> Option<usize> {
|
fn mirror_h(shape: &[Vec<char>], smudges: usize) -> Option<usize> {
|
||||||
(1..shape.len())
|
(1..shape.len()).find(|&i| {
|
||||||
.filter(|&i| {
|
|
||||||
shape
|
shape
|
||||||
.iter()
|
.iter()
|
||||||
.skip(i)
|
.skip(i)
|
||||||
|
@ -14,10 +13,10 @@ fn mirror_h(shape: &Vec<Vec<char>>, smudges: usize) -> Option<usize> {
|
||||||
.sum::<usize>()
|
.sum::<usize>()
|
||||||
== smudges
|
== smudges
|
||||||
})
|
})
|
||||||
.max()
|
|
||||||
}
|
}
|
||||||
fn mirror_v(shape: &Vec<Vec<char>>, smudges: usize) -> Option<usize> {
|
|
||||||
let shape = (0..shape[0].len())
|
fn mirror_v(shape: &[Vec<char>], smudges: usize) -> Option<usize> {
|
||||||
|
let shape: Vec<Vec<char>> = (0..shape[0].len())
|
||||||
.map(|col| (0..shape.len()).map(|row| shape[row][col]).collect())
|
.map(|col| (0..shape.len()).map(|row| shape[row][col]).collect())
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
|
@ -28,10 +27,9 @@ fn solve(input: &str, smudges: usize) -> usize {
|
||||||
input
|
input
|
||||||
.split("\n\n")
|
.split("\n\n")
|
||||||
.map(|x| x.lines().map(|line| line.chars().collect()).collect())
|
.map(|x| x.lines().map(|line| line.chars().collect()).collect())
|
||||||
.map(|shape| {
|
.map(|shape: Vec<Vec<char>>| {
|
||||||
let v = mirror_v(&shape, smudges).unwrap_or_default();
|
mirror_v(&shape, smudges).unwrap_or_default()
|
||||||
let h = mirror_h(&shape, smudges).unwrap_or_default();
|
+ mirror_h(&shape, smudges).unwrap_or_default() * 100
|
||||||
v + h * 100
|
|
||||||
})
|
})
|
||||||
.sum()
|
.sum()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue