diff --git a/2018/loc.svg b/2018/loc.svg
index d05c0b6..9666dd1 100644
--- a/2018/loc.svg
+++ b/2018/loc.svg
@@ -32,10 +32,10 @@ z
+" id="md180c468f1" style="stroke:#000000;stroke-width:0.8;"/>
-
+
@@ -71,7 +71,7 @@ z
-
+
@@ -110,7 +110,7 @@ z
-
+
@@ -139,7 +139,7 @@ z
-
+
@@ -153,7 +153,7 @@ z
-
+
@@ -193,7 +193,7 @@ z
-
+
@@ -286,10 +286,10 @@ z
+" id="mf0f7226eb2" style="stroke:#000000;stroke-width:0.8;"/>
-
+
@@ -302,7 +302,7 @@ L -3.5 0
-
+
@@ -316,7 +316,7 @@ L -3.5 0
-
+
@@ -331,7 +331,7 @@ L -3.5 0
-
+
@@ -346,7 +346,7 @@ L -3.5 0
-
+
@@ -361,7 +361,7 @@ L -3.5 0
-
+
@@ -577,7 +577,7 @@ z
-
-
-
+
diff --git a/2018/src/day17.rs b/2018/src/day17.rs
index a317fa1..dd484b7 100644
--- a/2018/src/day17.rs
+++ b/2018/src/day17.rs
@@ -60,33 +60,6 @@ impl Day17 {
};
}
- #[allow(unused)]
- fn map(&self) {
- let (xmin, xmax) = match self.clays.iter().map(|(x, _)| *x).minmax() {
- MinMaxResult::MinMax(a, b) => (a, b),
- _ => panic!(),
- };
-
- println!("{}, {} to {}, {}", xmin, self.ymin, xmax, self.ymax);
-
- for y in self.ymin..=self.ymax {
- let mut buf = String::with_capacity(xmax - xmin + 1);
- for x in xmin..=xmax {
- let pos = (x, y);
- if self.clays.contains(&pos) {
- buf.push('#');
- } else if self.contained.contains(&pos) {
- buf.push('~');
- } else if self.flowing.contains(&pos) {
- buf.push('|');
- } else {
- buf.push(' ');
- }
- }
- println!("{}", buf);
- }
- }
-
fn descend(&mut self, pos: Coordinate) {
let (x, y) = pos;
@@ -152,25 +125,21 @@ impl Solution for Day17 {
fn part1(&mut self, input: &mut Read) -> String {
self.read_input(input);
-
self.descend((500, 0));
- let range_filter = |&&(_, y): &&(usize, usize)| y >= self.ymin && y <= self.ymax;
-
- let result = self.contained.iter().filter(range_filter).count()
- + self.flowing.iter().filter(range_filter).count();
+ let result = self.contained.iter()
+ .chain(self.flowing.iter())
+ .filter(|&&(_, y)| y >= self.ymin && y <= self.ymax).count();
format!("{}", result)
}
fn part2(&mut self, input: &mut Read) -> String {
self.read_input(input);
-
self.descend((500, 0));
- let range_filter = |&&(_, y): &&(usize, usize)| y >= self.ymin && y <= self.ymax;
-
- let result = self.contained.iter().filter(range_filter).count();
+ let result = self.contained.iter()
+ .filter(|&&(_, y)| y >= self.ymin && y <= self.ymax).count();
format!("{}", result)
}
}