Almost done haha
This commit is contained in:
parent
10b594e479
commit
f4d2d3bf24
4 changed files with 327 additions and 4 deletions
|
@ -1,4 +1,3 @@
|
|||
extern crate core;
|
||||
|
||||
pub mod prob1;
|
||||
pub mod prob2;
|
||||
pub mod prob2;
|
||||
pub mod prob3;
|
|
@ -1,4 +1,4 @@
|
|||
use advent_of_code::{prob1, prob2};
|
||||
use advent_of_code::{prob1, prob2, prob3};
|
||||
|
||||
fn main() {
|
||||
{
|
||||
|
@ -13,4 +13,9 @@ fn main() {
|
|||
let max_part2 = prob2::solve_part2(file_path);
|
||||
println!("Solution for problem 2 part 1: {max_part1}\nSolution for problem 2 part 2: {max_part2}");
|
||||
}
|
||||
{
|
||||
let file_path = "prob3_part1.txt";
|
||||
let max_part1 = prob3::solve_part1(file_path);
|
||||
println!("{max_part1}");
|
||||
}
|
||||
}
|
||||
|
|
19
src/prob3/mod.rs
Normal file
19
src/prob3/mod.rs
Normal file
|
@ -0,0 +1,19 @@
|
|||
use std::collections::HashSet;
|
||||
|
||||
pub fn solve_part1(file_path: &str) -> i32 {
|
||||
let binding =
|
||||
std::fs::read_to_string(file_path).expect("Please provide a text file as an argument.");
|
||||
let content = binding
|
||||
.lines()
|
||||
.collect::<Vec<&str>>()
|
||||
.iter()
|
||||
.map(|item: &&str| {
|
||||
let (first, last) = item.split_at(item.len() / 2);
|
||||
let second = last.chars().collect::<HashSet<char>>();
|
||||
let intersection = first.chars().collect::<HashSet<char>>();
|
||||
*intersection.intersection(&second).next().unwrap()
|
||||
})
|
||||
.collect::<Vec<char>>();
|
||||
|
||||
0
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue