day10: performance. slight gain from memoizing visited positions in p1.
This commit is contained in:
		| @@ -58,9 +58,13 @@ impl TrailMap { | |||||||
|             .collect_vec() |             .collect_vec() | ||||||
|     } |     } | ||||||
|     fn count_reachable_from(&self, pos: &(i64, i64), needle: u8, visited: &mut Grid<bool>) -> u64 { |     fn count_reachable_from(&self, pos: &(i64, i64), needle: u8, visited: &mut Grid<bool>) -> u64 { | ||||||
|         let our_val = self.map.get(pos.0, pos.1).unwrap(); |         if visited.get(pos.0, pos.1) == Some(true) { | ||||||
|         if our_val == needle && visited.get(pos.0, pos.1) == Some(false) { |             return 0; | ||||||
|  |         } else { | ||||||
|             visited.set(pos.0, pos.1, true); |             visited.set(pos.0, pos.1, true); | ||||||
|  |         } | ||||||
|  |         let our_val = self.map.get(pos.0, pos.1).unwrap(); | ||||||
|  |         if our_val == needle { | ||||||
|             return 1; |             return 1; | ||||||
|         } else if our_val == needle { |         } else if our_val == needle { | ||||||
|             return 0; |             return 0; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user