day02-2 super-fast
This commit is contained in:
@@ -51,6 +51,30 @@ pub fn task2() {
|
||||
println!("Part 2: None found!");
|
||||
}
|
||||
|
||||
pub fn task2_linear_asterisk() {
|
||||
let input = utils::read_file("input/day02.txt");
|
||||
|
||||
let mut hashes =
|
||||
HashSet::<String>::with_capacity(input.len() * input.lines().next().unwrap().len());
|
||||
|
||||
for line in input.lines() {
|
||||
for i in 0..line.len() {
|
||||
let string: String = line
|
||||
.chars()
|
||||
.enumerate()
|
||||
.map(|(index, c)| if index == i { '*' } else { c })
|
||||
.collect();
|
||||
|
||||
if hashes.contains(&string) {
|
||||
println!("{} is double", string);
|
||||
return;
|
||||
} else {
|
||||
hashes.insert(string);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn task2_linear() {
|
||||
let input = utils::read_file("input/day02.txt");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user