mirror of
https://github.com/bertptrs/adventofcode.git
synced 2025-12-25 21:00:31 +01:00
Clean up day 06.
This commit is contained in:
@@ -29,8 +29,6 @@ fn least_frequent(counts: &HashMap<char, i32>) -> char
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
println!("Hello, world!");
|
|
||||||
|
|
||||||
let args: Vec<String> = env::args().collect();
|
let args: Vec<String> = env::args().collect();
|
||||||
let f = File::open(&args[1]).expect("Could not open file");
|
let f = File::open(&args[1]).expect("Could not open file");
|
||||||
let reader = BufReader::new(f);
|
let reader = BufReader::new(f);
|
||||||
@@ -39,17 +37,12 @@ fn main() {
|
|||||||
|
|
||||||
for line in reader.lines() {
|
for line in reader.lines() {
|
||||||
for (i, c) in line.unwrap().trim().chars().enumerate() {
|
for (i, c) in line.unwrap().trim().chars().enumerate() {
|
||||||
let pos = i as usize;
|
if i >= counts.len() {
|
||||||
if pos >= counts.len() {
|
|
||||||
counts.push(HashMap::new());
|
counts.push(HashMap::new());
|
||||||
}
|
}
|
||||||
|
|
||||||
if ! counts[pos].contains_key(&c) {
|
let cur = counts[i].entry(c).or_insert(0);
|
||||||
counts[pos].insert(c, 1);
|
*cur += 1;
|
||||||
} else {
|
|
||||||
let cur = counts[pos][&c];
|
|
||||||
counts[pos].insert(c, cur + 1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user