Skip to content

Commit

Permalink
feat: solve 01/2024 part 1
Browse files Browse the repository at this point in the history
  • Loading branch information
manhunto committed Dec 1, 2024
1 parent 6e41853 commit e2fe058
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
7 changes: 4 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# How to run

* `cargo run -- -d1 -y2024 solve` - solve puzzle for a given day and year
* `cargo run -- -d1 -y2024 solve -a1` - solve puzzle for a given day and year and submit answer for part 1 to AoC server
* `cargo run -- -d1 -y2024 input` - download and save input for given puzzle
Expand All @@ -8,9 +9,9 @@

# 2024

| Day | Solved | Part 1 time (ms) | Part 2 time (ms) |
|-----|:------:|-----------------:|-----------------:|
| | | | |
| Day | Solved | Part 1 time (ms) | Part 2 time (ms) |
|---------------------------------------------------------------|:------:|-----------------:|-----------------:|
| [Day 1: Historian Hysteria ](src/solutions/year2024/day01.rs) | | 0.221 | |

# 2023

Expand Down
31 changes: 27 additions & 4 deletions src/solutions/year2024/day01.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,26 @@ use crate::solutions::Solution;
pub struct Day01;

impl Solution for Day01 {
fn part_one(&self, _input: &str) -> String {
String::new()
fn part_one(&self, input: &str) -> String {
let (mut left, mut right): (Vec<i32>, Vec<i32>) = input
.lines()
.map(|line| {
let mut split = line.split_terminator(" ");
(
split.next().unwrap().parse::<i32>().unwrap(),
split.next().unwrap().parse::<i32>().unwrap(),
)
})
.unzip();

left.sort_unstable();
right.sort_unstable();

left.iter()
.zip(right.iter())
.map(|(a, b)| (a - b).abs())
.sum::<i32>()
.to_string()
}

fn part_two(&self, _input: &str) -> String {
Expand All @@ -17,10 +35,15 @@ mod tests {
use crate::solutions::year2024::day01::Day01;
use crate::solutions::Solution;

const EXAMPLE: &str = "";
const EXAMPLE: &str = r#"3 4
4 3
2 5
1 3
3 9
3 3"#;

#[test]
fn part_one_example_test() {
assert_eq!("", Day01.part_one(EXAMPLE));
assert_eq!("11", Day01.part_one(EXAMPLE));
}
}

0 comments on commit e2fe058

Please sign in to comment.