Compare commits
No commits in common. "befbc009cc8d3ebfd8e3ff8899a22dc1414a9069" and "0b28444120df17eab8d4447a8636a8ba161c264e" have entirely different histories.
befbc009cc
...
0b28444120
5 changed files with 9 additions and 66 deletions
14
.gitignore
vendored
14
.gitignore
vendored
|
@ -1,16 +1,2 @@
|
|||
/target
|
||||
.idea
|
||||
# Generated by Cargo
|
||||
# will have compiled files and executables
|
||||
debug/
|
||||
target/
|
||||
|
||||
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
|
||||
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
|
||||
Cargo.lock
|
||||
|
||||
# These are backup files generated by rustfmt
|
||||
**/*.rs.bk
|
||||
|
||||
# MSVC Windows builds of rustc generate these, which store debugging information
|
||||
*.pdb
|
||||
|
|
7
Cargo.lock
generated
Normal file
7
Cargo.lock
generated
Normal file
|
@ -0,0 +1,7 @@
|
|||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "advent_of_code"
|
||||
version = "0.1.0"
|
|
@ -5,9 +5,4 @@ edition = "2021"
|
|||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[profile.release-perso]
|
||||
inherits = "release"
|
||||
incremental = true
|
||||
rpath = true
|
||||
|
||||
[dependencies]
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use advent_of_code::{prob1, prob2, prob3, prob4};
|
||||
use advent_of_code::{prob1, prob2, prob3};
|
||||
|
||||
fn main() {
|
||||
{
|
||||
|
@ -23,9 +23,4 @@ fn main() {
|
|||
let max_part2 = prob3::solve_part2(file_path);
|
||||
println!("Solution for problem 3 part 2: {max_part2}");
|
||||
}
|
||||
{
|
||||
let file_path = "prob4_part1.txt";
|
||||
let max_part1 = prob4::solve_part1(file_path);
|
||||
println!("Solution for problem 4 part 1: {max_part1}");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,40 +0,0 @@
|
|||
fn mutual_inclusion(first_pair: &[u32], second_pair: &[u32]) -> bool {
|
||||
(first_pair[0] <= second_pair[0] && first_pair[1] >= second_pair[1])
|
||||
|| (second_pair[0] <= first_pair[0] && second_pair[1] >= first_pair[1])
|
||||
}
|
||||
|
||||
pub fn solve_part1(file_path: &str) -> i32 {
|
||||
let result = std::fs::read_to_string(file_path)
|
||||
.expect("Please provide a text file as an argument.")
|
||||
.lines()
|
||||
.map(|line| {
|
||||
let tmp = line.split(',').collect::<Vec<&str>>();
|
||||
let firs_pair = tmp
|
||||
.first()
|
||||
.expect("First character error")
|
||||
.split('-')
|
||||
.map(|first_split| {
|
||||
first_split
|
||||
.parse::<u32>()
|
||||
.expect("Parsing number in first pair failed")
|
||||
})
|
||||
.collect::<Vec<u32>>();
|
||||
let second_pair = tmp
|
||||
.last()
|
||||
.expect("First character error")
|
||||
.split('-')
|
||||
.map(|first_split| {
|
||||
first_split
|
||||
.parse::<u32>()
|
||||
.expect("Parsing number in first pair failed")
|
||||
})
|
||||
.collect::<Vec<u32>>();
|
||||
if mutual_inclusion(&firs_pair, &second_pair) {
|
||||
1
|
||||
} else {
|
||||
0
|
||||
}
|
||||
})
|
||||
.collect::<Vec<i32>>();
|
||||
result.iter().sum()
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue