summaryrefslogtreecommitdiff
path: root/2024_rust/src
diff options
context:
space:
mode:
authorGuillermo Ramos2024-12-06 15:59:32 +0100
committerGuillermo Ramos2024-12-06 16:29:18 +0100
commitff064b6f13019b15346ff320a486d70b95d80b2a (patch)
tree396868cbbd9be95f6ce0a808f8436d4a1a0f1d89 /2024_rust/src
parenta6029017bb354381c17afaf00526442966648c3f (diff)
downloadAoC-ff064b6f13019b15346ff320a486d70b95d80b2a.tar.gz
Each day is now a binary
Diffstat (limited to '2024_rust/src')
-rw-r--r--2024_rust/src/bin/day1.rs (renamed from 2024_rust/src/day1.rs)8
-rw-r--r--2024_rust/src/bin/day2.rs (renamed from 2024_rust/src/day2.rs)8
-rw-r--r--2024_rust/src/bin/day3.rs (renamed from 2024_rust/src/day3.rs)8
-rw-r--r--2024_rust/src/bin/day4.rs (renamed from 2024_rust/src/day4.rs)8
-rw-r--r--2024_rust/src/bin/day5.rs (renamed from 2024_rust/src/day5.rs)8
-rw-r--r--2024_rust/src/bin/dayN.rs15
-rw-r--r--2024_rust/src/dayN.rs11
-rw-r--r--2024_rust/src/lib.rs12
-rw-r--r--2024_rust/src/main.rs10
9 files changed, 57 insertions, 31 deletions
diff --git a/2024_rust/src/day1.rs b/2024_rust/src/bin/day1.rs
index 0b6c13d..2e0f01d 100644
--- a/2024_rust/src/day1.rs
+++ b/2024_rust/src/bin/day1.rs
@@ -1,4 +1,4 @@
-pub fn p1(input: &str) -> String {
+fn p1(input: &str) -> String {
let mut left: Vec<u32> = vec![];
let mut right: Vec<u32> = vec![];
for line in input.lines() {
@@ -22,7 +22,7 @@ pub fn p1(input: &str) -> String {
use std::collections::HashMap;
-pub fn p2(input: &str) -> String {
+fn p2(input: &str) -> String {
let mut left: Vec<u32> = vec![];
let mut right: HashMap<u32, u32> = HashMap::new();
for line in input.lines() {
@@ -43,3 +43,7 @@ pub fn p2(input: &str) -> String {
distance.to_string()
}
+
+fn main() {
+ aoc2024::run_day("1", p1, p2);
+}
diff --git a/2024_rust/src/day2.rs b/2024_rust/src/bin/day2.rs
index f809141..92d288f 100644
--- a/2024_rust/src/day2.rs
+++ b/2024_rust/src/bin/day2.rs
@@ -23,7 +23,7 @@ fn is_safe(levels: &[u32]) -> bool {
return true;
}
-pub fn p1(input: &str) -> String {
+fn p1(input: &str) -> String {
let mut total = 0;
for report in input.lines() {
let levels: Vec<u32> = report
@@ -49,7 +49,7 @@ fn is_safe_with_dampener(levels: &[u32]) -> bool {
return false;
}
-pub fn p2(input: &str) -> String {
+fn p2(input: &str) -> String {
let mut total = 0;
for report in input.lines() {
let levels: Vec<u32> = report
@@ -63,3 +63,7 @@ pub fn p2(input: &str) -> String {
total.to_string()
}
+
+fn main() {
+ aoc2024::run_day("2", p1, p2);
+}
diff --git a/2024_rust/src/day3.rs b/2024_rust/src/bin/day3.rs
index cdcd62a..1eedefe 100644
--- a/2024_rust/src/day3.rs
+++ b/2024_rust/src/bin/day3.rs
@@ -1,6 +1,6 @@
use regex::Regex;
-pub fn p1(input: &str) -> String {
+fn p1(input: &str) -> String {
let re = Regex::new(r"mul\(([0-9]{1,3}),([0-9]{1,3})\)").unwrap();
let mut result: u32 = 0;
@@ -11,7 +11,7 @@ pub fn p1(input: &str) -> String {
result.to_string()
}
-pub fn p2(input: &str) -> String {
+fn p2(input: &str) -> String {
let re = Regex::new(r"do\(\)|don't\(\)|mul\(([0-9]{1,3}),([0-9]{1,3})\)").unwrap();
let mut doing = true;
@@ -31,3 +31,7 @@ pub fn p2(input: &str) -> String {
result.to_string()
}
+
+fn main() {
+ aoc2024::run_day("3", p1, p2);
+}
diff --git a/2024_rust/src/day4.rs b/2024_rust/src/bin/day4.rs
index 448fe19..7eb7b7a 100644
--- a/2024_rust/src/day4.rs
+++ b/2024_rust/src/bin/day4.rs
@@ -86,7 +86,7 @@ fn moves_xmas(Square { pos, size, .. }: &Square) -> Vec<Move> {
v
}
-pub fn p1(input: &str) -> String {
+fn p1(input: &str) -> String {
let matrix: Matrix = Matrix::new(input);
let mut result = 0;
@@ -116,7 +116,7 @@ fn moves_mas(Square { pos, size, .. }: &Square) -> Vec<Move> {
v
}
-pub fn p2(input: &str) -> String {
+fn p2(input: &str) -> String {
let matrix: Matrix = Matrix::new(input);
let mut result = 0;
@@ -135,3 +135,7 @@ pub fn p2(input: &str) -> String {
result.to_string()
}
+
+fn main() {
+ aoc2024::run_day("4", p1, p2);
+}
diff --git a/2024_rust/src/day5.rs b/2024_rust/src/bin/day5.rs
index e13f8e5..fe22295 100644
--- a/2024_rust/src/day5.rs
+++ b/2024_rust/src/bin/day5.rs
@@ -135,7 +135,7 @@ fn sum_valid_updates(Input { rules, updates }: &Input) -> u32 {
.sum()
}
-pub fn p1(input: &str) -> String {
+fn p1(input: &str) -> String {
let input = Input::from_str(input).unwrap();
sum_valid_updates(&input).to_string()
}
@@ -214,7 +214,11 @@ fn sum_reordered_updates(Input { rules, updates }: &Input) -> u32 {
.sum()
}
-pub fn p2(input: &str) -> String {
+fn p2(input: &str) -> String {
let input = Input::from_str(input).unwrap();
sum_reordered_updates(&input).to_string()
}
+
+fn main() {
+ aoc2024::run_day("5", p1, p2);
+}
diff --git a/2024_rust/src/bin/dayN.rs b/2024_rust/src/bin/dayN.rs
new file mode 100644
index 0000000..cdaa061
--- /dev/null
+++ b/2024_rust/src/bin/dayN.rs
@@ -0,0 +1,15 @@
+fn p1(_input: &str) -> String {
+ let result = "TODO";
+
+ result.to_string()
+}
+
+fn p2(_input: &str) -> String {
+ let result = "TODO";
+
+ result.to_string()
+}
+
+fn main() {
+ aoc2024::run_day("N", p1, p2);
+}
diff --git a/2024_rust/src/dayN.rs b/2024_rust/src/dayN.rs
deleted file mode 100644
index d325291..0000000
--- a/2024_rust/src/dayN.rs
+++ /dev/null
@@ -1,11 +0,0 @@
-pub fn p1(input: &str) -> String {
- let result = "TODO";
-
- result.to_string()
-}
-
-pub fn p2(input: &str) -> String {
- let result = "TODO";
-
- result.to_string()
-}
diff --git a/2024_rust/src/lib.rs b/2024_rust/src/lib.rs
new file mode 100644
index 0000000..f8a84d6
--- /dev/null
+++ b/2024_rust/src/lib.rs
@@ -0,0 +1,12 @@
+pub fn run_day<S1, S2>(day: &str, p1: S1, p2: S2)
+where
+ S1: FnOnce(&str) -> String,
+ S2: FnOnce(&str) -> String,
+{
+ let input_file = format!("inputs/{day}");
+ let input = std::fs::read_to_string(input_file).unwrap();
+
+ println!("==== DAY {day}");
+ println!("Result (P1): {}", p1(&input));
+ println!("Result (P2): {}", p2(&input));
+}
diff --git a/2024_rust/src/main.rs b/2024_rust/src/main.rs
deleted file mode 100644
index 4c5e7fd..0000000
--- a/2024_rust/src/main.rs
+++ /dev/null
@@ -1,10 +0,0 @@
-mod day5;
-use day5 as current_day;
-const INPUT_FILE: &str = "inputs/5";
-
-fn main() {
- let input = std::fs::read_to_string(INPUT_FILE).unwrap();
-
- println!("Result (P1): {}", current_day::p1(&input));
- println!("Result (P2): {}", current_day::p2(&input));
-}