This commit is contained in:
Kevin Cotugno 2018-12-04 10:34:03 -08:00
parent 9b8409e44d
commit 6ee5221f11
4 changed files with 25 additions and 21 deletions

2
Cargo.lock generated
View File

@ -1,4 +1,4 @@
[[package]]
name = "AoC-2018"
name = "aoc-2018"
version = "0.1.0"

View File

@ -1,10 +1,10 @@
[package]
name = "AoC-2018"
name = "aoc-2018"
version = "0.1.0"
authors = ["Kevin Cotugno <kevin@kevincotugno.com>"]
[[bin]]
name = "AoC-2018"
name = "aoc-2018"
path = "src/bin/main.rs"
[lib]

View File

@ -17,19 +17,19 @@ fn c_02_1(input: &[&str]) -> i32 {
for c in val.chars() {
let new_val = match m.get(&c) {
Some(v) => *v + 1,
None => 1
None => 1,
};
m.insert(c.clone(), new_val);
m.insert(c, new_val);
}
three += match m.iter().filter(|(_, v)| **v == 3).next() {
three += match m.iter().find(|(_, v)| **v == 3) {
Some(_) => 1,
None => 0
None => 0,
};
two += match m.iter().filter(|(_, v)| **v == 2).next() {
two += match m.iter().find(|(_, v)| **v == 2) {
Some(_) => 1,
None => 0
None => 0,
};
}
@ -42,16 +42,13 @@ fn c_02_2(input: &[&str]) -> String {
let mut diff = 0;
let mut val2char = val2.chars();
for val1char in val1.chars() {
match val2char.next() {
Some(v) => {
if let Some(v) = val2char.next() {
if v != val1char {
diff += 1;
if diff > 1 {
break;
}
}
},
None => ()
}
}

View File

@ -20,5 +20,12 @@ fn main() {
.map(|v| v.to_string())
.collect();
println!("{}", aoc::run(&(lines.iter().map(|s| s.as_str()).collect::<Vec<&str>>() ), challenge, part));
println!(
"{}",
aoc::run(
&(lines.iter().map(|s| s.as_str()).collect::<Vec<&str>>()),
challenge,
part
)
);
}