generated from fspoettel/advent-of-code-rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6d92f1b
commit e885a3c
Showing
10 changed files
with
124 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
3 4 | ||
4 3 | ||
2 5 | ||
1 3 | ||
3 9 | ||
3 3 |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
use std::collections::HashMap; | ||
|
||
advent_of_code::solution!(1); | ||
|
||
pub fn part_one(input: &str) -> Option<u32> { | ||
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<u32> { | ||
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)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
advent_of_code::solution!(2); | ||
|
||
pub fn part_one(input: &str) -> Option<u32> { | ||
None | ||
} | ||
|
||
pub fn part_two(input: &str) -> Option<u32> { | ||
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); | ||
} | ||
} |