diff --git a/.cargo/config.toml b/.cargo/config.toml index 66b873e..cf0d80d 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -9,4 +9,4 @@ all = "run --quiet --release -- all" time = "run --quiet --release -- time" [env] -AOC_YEAR = "2023" +AOC_YEAR = "2024" diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json deleted file mode 100644 index 6043626..0000000 --- a/.devcontainer/devcontainer.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "name": "rust-devcontainer", - "image": "mcr.microsoft.com/devcontainers/rust:latest", - "postCreateCommand": "rustc --version", - "remoteUser": "vscode" -} diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 560e94b..0000000 --- a/.editorconfig +++ /dev/null @@ -1,17 +0,0 @@ -# EditorConfig is awesome: http://EditorConfig.org -root = true - -[*] -indent_size = 4 -indent_style = space -end_of_line = lf -charset = utf-8 -insert_final_newline = true -trim_trailing_whitespace = true - -[*.txt] -insert_final_newline = false -trim_trailing_whitespace = false - -[*.md] -trim_trailing_whitespace = false diff --git a/.github/workflows/readme-stars.yml b/.github/workflows/readme-stars.yml index 3de260e..29d8136 100644 --- a/.github/workflows/readme-stars.yml +++ b/.github/workflows/readme-stars.yml @@ -1,24 +1,25 @@ name: Update readme ⭐️ progress on: - # !Please set a different minute than 51 if you enable this! - # schedule: - # - cron: "51 */6 * * *" # Every 6 hours - workflow_dispatch: + # !Please set a different minute than 51 if you enable this! + # schedule: + # - cron: "51 */6 * * *" # Every 6 hours + push: + workflow_dispatch: jobs: - update-readme: - runs-on: ubuntu-latest - if: ${{ vars.AOC_ENABLED == 'true' }} - permissions: - contents: write - steps: - - uses: actions/checkout@v4 - - uses: k2bd/advent-readme-stars@v1 - with: - userId: ${{ secrets.AOC_USER_ID }} - sessionCookie: ${{ secrets.AOC_SESSION }} - year: ${{ secrets.AOC_YEAR }} - - uses: stefanzweifel/git-auto-commit-action@v5 - with: - commit_message: "update readme progress" + update-readme: + runs-on: ubuntu-latest + if: ${{ vars.AOC_ENABLED == 'true' }} + permissions: + contents: write + steps: + - uses: actions/checkout@v4 + - uses: k2bd/advent-readme-stars@v1 + with: + userId: ${{ secrets.AOC_USER_ID }} + sessionCookie: ${{ secrets.AOC_SESSION }} + year: ${{ secrets.AOC_YEAR }} + - uses: stefanzweifel/git-auto-commit-action@v5 + with: + commit_message: "update readme progress" diff --git a/.vscode/extensions.json b/.vscode/extensions.json deleted file mode 100644 index 996c817..0000000 --- a/.vscode/extensions.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "recommendations": [ - "vadimcn.vscode-lldb", - "rust-lang.rust-analyzer", - "editorConfig.editorConfig" - ] -} diff --git a/.vscode/launch.json b/.vscode/launch.json deleted file mode 100644 index 8f244cf..0000000 --- a/.vscode/launch.json +++ /dev/null @@ -1,58 +0,0 @@ -{ - // Use IntelliSense to learn about possible attributes. - // Hover to view descriptions of existing attributes. - // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 - "version": "0.2.0", - "configurations": [ - { - "type": "lldb", - "request": "launch", - "name": "Debug unit tests for a solution", - "cargo": { - "args": [ - "test", - "--no-run", - // replace `01` here with the solution you like to debug. - "--bin=01", - "--package=advent_of_code" - ], - }, - "args": [], - "cwd": "${workspaceFolder}" - }, - { - "type": "lldb", - "request": "launch", - "name": "Debug a solution", - "cargo": { - "args": [ - "build", - // replace `01` here with the solution you like to debug. - "--bin=01", - "--package=advent_of_code" - ], - }, - "cwd": "${workspaceFolder}" - }, - { - "type": "lldb", - "request": "launch", - "name": "Debug unit tests in library 'advent_of_code'", - "cargo": { - "args": [ - "test", - "--no-run", - "--lib", - "--features=test_lib", - "--package=advent_of_code" - ], - "filter": { - "name": "advent_of_code", - "kind": "lib" - } - }, - "args": [], - "cwd": "${workspaceFolder}" - } - ] -} diff --git a/data/examples/01.txt b/data/examples/01.txt new file mode 100644 index 0000000..b8af9ad --- /dev/null +++ b/data/examples/01.txt @@ -0,0 +1,6 @@ +3 4 +4 3 +2 5 +1 3 +3 9 +3 3 diff --git a/data/examples/02.txt b/data/examples/02.txt new file mode 100644 index 0000000..e69de29 diff --git a/src/bin/01.rs b/src/bin/01.rs new file mode 100644 index 0000000..46a0824 --- /dev/null +++ b/src/bin/01.rs @@ -0,0 +1,71 @@ +use std::collections::HashMap; + +advent_of_code::solution!(1); + +pub fn part_one(input: &str) -> Option { + let mut left = vec![]; + let mut right = vec![]; + for line in input.lines() { + let (left_int, right_int): (u32, u32) = line + .split_once(" ") + .map(|(a, b)| (a.parse().unwrap(), b.parse().unwrap())) + .unwrap(); + left.push(left_int); + right.push(right_int); + } + left.sort_unstable(); + right.sort_unstable(); + + let mut diff = 0; + for idx in 0..left.len() { + let l_el = left.get(idx).unwrap(); + let r_el = right.get(idx).unwrap(); + + if l_el > r_el { + diff += l_el - r_el; + } else { + diff += r_el - l_el; + } + } + Some(diff) +} + +pub fn part_two(input: &str) -> Option { + let mut left = vec![]; + let mut right = HashMap::new(); + for line in input.lines() { + let (left_int, right_int): (u32, u32) = line + .split_once(" ") + .map(|(a, b)| (a.parse().unwrap(), b.parse().unwrap())) + .unwrap(); + left.push(left_int); + *right.entry(right_int).or_insert(0) += 1; + } + left.sort_unstable(); + + let mut diff = 0; + for idx in 0..left.len() { + let l_el = left.get(idx).unwrap(); + let r_el = right.get(l_el).unwrap_or(&0); + + diff += l_el * r_el; + } + Some(diff) +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_part_one() { + let result = part_one(&advent_of_code::template::read_file("examples", DAY)); + assert_eq!(result, Some(11)); + } + + #[test] + fn test_part_two() { + let result = part_two(&advent_of_code::template::read_file("examples", DAY)); + assert_eq!(result, Some(31)); + } +} diff --git a/src/bin/02.rs b/src/bin/02.rs new file mode 100644 index 0000000..3bae35c --- /dev/null +++ b/src/bin/02.rs @@ -0,0 +1,26 @@ +advent_of_code::solution!(2); + +pub fn part_one(input: &str) -> Option { + None +} + +pub fn part_two(input: &str) -> Option { + None +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_part_one() { + let result = part_one(&advent_of_code::template::read_file("examples", DAY)); + assert_eq!(result, None); + } + + #[test] + fn test_part_two() { + let result = part_two(&advent_of_code::template::read_file("examples", DAY)); + assert_eq!(result, None); + } +}