mirror of
https://github.com/bertptrs/adventofcode.git
synced 2025-12-26 21:30:31 +01:00
Refactor grouping count into a trait.
This commit is contained in:
@@ -3,9 +3,11 @@ use std::io;
|
||||
use std::io::BufRead;
|
||||
use std::ops::Range;
|
||||
|
||||
use common;
|
||||
use regex;
|
||||
|
||||
use common;
|
||||
use common::GroupingCount;
|
||||
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
struct Claim {
|
||||
x: usize,
|
||||
@@ -60,15 +62,10 @@ impl Day03 {
|
||||
}
|
||||
}
|
||||
|
||||
fn get_claims(&self) -> HashMap<(usize, usize), i32> {
|
||||
let mut claims = HashMap::new();
|
||||
for claim in &self.claims {
|
||||
for coordinate in claim.range() {
|
||||
*claims.entry(coordinate).or_insert(0) += 1;
|
||||
}
|
||||
}
|
||||
|
||||
claims
|
||||
fn get_claims(&self) -> HashMap<(usize, usize), usize> {
|
||||
self.claims.iter()
|
||||
.flat_map(|x| x.range())
|
||||
.grouping_count()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user