-
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
c84dd5e
commit f340e17
Showing
4 changed files
with
102 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
47|53 | ||
97|13 | ||
97|61 | ||
97|47 | ||
75|29 | ||
61|13 | ||
75|53 | ||
29|13 | ||
97|29 | ||
53|29 | ||
61|53 | ||
97|53 | ||
61|29 | ||
47|13 | ||
75|47 | ||
97|75 | ||
47|61 | ||
75|61 | ||
47|29 | ||
75|13 | ||
53|13 | ||
|
||
75,47,61,53,29 | ||
97,61,53,29,13 | ||
75,29,13 | ||
75,97,47,61,53 | ||
61,13,29 | ||
97,13,75,29,47 |
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 |
---|---|---|
|
@@ -18,5 +18,10 @@ | |
"day": 4, | ||
"part1": "2591", | ||
"part2": "1880" | ||
}, | ||
{ | ||
"day": 5, | ||
"part1": "6041", | ||
"part2": "" | ||
} | ||
] |
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,67 @@ | ||
use crate::aoc2024::Aoc2024; | ||
use crate::traits::days::Day5; | ||
use crate::traits::ParseInput; | ||
use crate::traits::Solution; | ||
|
||
impl ParseInput<Day5> for Aoc2024 { | ||
type Parsed = Input; | ||
|
||
fn parse_input(input: &str) -> Self::Parsed { | ||
let mut is_in_pages = false; | ||
let mut res = Input::default(); | ||
|
||
for line in input.lines() { | ||
let line = line.trim(); | ||
if line.is_empty() { | ||
is_in_pages = true; | ||
continue; | ||
} | ||
|
||
if !is_in_pages { | ||
let (left, right) = line.split_once("|").unwrap(); | ||
let left = left.parse().unwrap(); | ||
let right = right.parse().unwrap(); | ||
let pair = (left, right); | ||
res.pairs.push(pair); | ||
} else { | ||
let page = line.split(',').map(|s| s.parse().unwrap()).collect(); | ||
res.pages.push(page); | ||
} | ||
} | ||
|
||
res | ||
} | ||
} | ||
#[derive(Debug, Default)] | ||
pub struct Input { | ||
pairs: Vec<(u32, u32)>, | ||
pages: Vec<Vec<u32>>, | ||
} | ||
|
||
impl Solution<Day5> for Aoc2024 { | ||
type Part1Output = u32; | ||
type Part2Output = u32; | ||
|
||
fn part1(input: &Input) -> u32 { | ||
let mut res = 0; | ||
|
||
'page: for page in &input.pages { | ||
for (i, left) in page.iter().enumerate() { | ||
for right in page[i + 1..].iter() { | ||
let rev_pair = (*right, *left); | ||
if input.pairs.contains(&rev_pair) { | ||
continue 'page; | ||
} | ||
} | ||
} | ||
|
||
let mid = page.len() / 2 ; | ||
res += page[mid]; | ||
} | ||
res | ||
} | ||
|
||
fn part2(input: &Input) -> u32 { | ||
todo!() | ||
} | ||
} |
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