1
0
Fork 0

End of day commit, nothing works. Will be using a parsing library (nom)

This commit is contained in:
Pcornat 2022-12-11 21:43:38 +01:00
parent 660cca5d23
commit 0408d3e148
Signed by: Pcornat
GPG key ID: 2F3932FF46D9ECA0
5 changed files with 543 additions and 2 deletions

View file

@ -1,4 +1,5 @@
pub mod prob1;
pub mod prob2;
pub mod prob3;
pub mod prob4;
pub mod prob4;
pub mod prob5;

View file

@ -1,4 +1,4 @@
use advent_of_code::{prob1, prob2, prob3, prob4};
use advent_of_code::{prob1, prob2, prob3, prob4, prob5};
fn main() {
{
@ -33,4 +33,9 @@ fn main() {
let max_part1 = prob4::solve(file_path, &prob4::complete_overlap);
println!("Solution for problem 4 part 2: {max_part1}");
}
{
let file_path = "prob5_part1.txt";
let max_part1 = prob5::solve(file_path);
println!("Solution for problem 5 part 1: {max_part1}");
}
}

23
src/prob5.rs Normal file
View file

@ -0,0 +1,23 @@
fn parser(content: &str) {
let output = content
.lines()
.filter(|item| !item.starts_with("move"))
.flat_map(|line| {
let splitted = line
.trim()
.split(' ')
.enumerate()
.filter(|item| !item.1.contains(' '))
.filter(|item| !item.1.is_empty())
.collect::<Vec<(usize, &str)>>();
println!("{splitted:?}");
splitted
})
.collect::<Vec<(usize, &str)>>();
}
pub fn solve(file_path: &str) -> i32 {
let content = std::fs::read_to_string(file_path).expect("Please provide a file.");
parser(&content);
0
}