day 8 part 2
This commit is contained in:
43
src/day08.rs
43
src/day08.rs
@@ -20,7 +20,7 @@ fn part1(input: &str) -> RiddleResult {
|
|||||||
.entries()
|
.entries()
|
||||||
.filter(|(_, c)| **c != '.')
|
.filter(|(_, c)| **c != '.')
|
||||||
.into_group_map_by(|(_, c)| *c);
|
.into_group_map_by(|(_, c)| *c);
|
||||||
for (frequency, coords) in antennas {
|
for (_, coords) in antennas {
|
||||||
for (a, _) in coords.iter() {
|
for (a, _) in coords.iter() {
|
||||||
for (b, _) in coords.iter() {
|
for (b, _) in coords.iter() {
|
||||||
if a == b {
|
if a == b {
|
||||||
@@ -38,8 +38,43 @@ fn part1(input: &str) -> RiddleResult {
|
|||||||
antinodes.len()
|
antinodes.len()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn part2(_input: &str) -> RiddleResult {
|
fn part2(input: &str) -> RiddleResult {
|
||||||
0
|
let grid = Grid::parse(input);
|
||||||
|
let mut antinodes = HashSet::new();
|
||||||
|
let antennas = grid
|
||||||
|
.entries()
|
||||||
|
.filter(|(_, c)| **c != '.')
|
||||||
|
.into_group_map_by(|(_, c)| *c);
|
||||||
|
for (_, coords) in antennas {
|
||||||
|
for (a, _) in coords.iter() {
|
||||||
|
for (b, _) in coords.iter() {
|
||||||
|
if a == b {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
antinodes.insert(*a);
|
||||||
|
antinodes.insert(*b);
|
||||||
|
let dx = a.0 - b.0;
|
||||||
|
let dy = a.1 - b.1;
|
||||||
|
for i in 1.. {
|
||||||
|
let p = (a.0 + i * dx, a.1 + i * dy);
|
||||||
|
if grid.contains_key(p) {
|
||||||
|
antinodes.insert(p);
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for i in 1.. {
|
||||||
|
let p = (a.0 - i * dx, a.1 - i * dy);
|
||||||
|
if grid.contains_key(p) {
|
||||||
|
antinodes.insert(p);
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
antinodes.len()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
@@ -67,6 +102,6 @@ mod test {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test2() {
|
fn test2() {
|
||||||
assert_eq!(part2(TEST_INPUT), 0);
|
assert_eq!(part2(TEST_INPUT), 34);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user