-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
A fairly dodgy answer to Day02 Part1
- Loading branch information
1 parent
c076819
commit 4f85fed
Showing
6 changed files
with
74 additions
and
1 deletion.
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 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 |
---|---|---|
|
@@ -25,4 +25,5 @@ pub mod year2023 { | |
|
||
pub mod year2024 { | ||
pub mod day01; | ||
pub mod day02; | ||
} |
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 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,38 @@ | ||
#![warn(clippy::pedantic, clippy::nursery)] | ||
|
||
use crate::util::parse; | ||
|
||
#[must_use] | ||
pub fn parse(input: &str) -> Vec<Vec<u32>> { | ||
input | ||
.lines() | ||
.map(|line| { | ||
parse::ParseUnsigned::<u32>::new(line.bytes()).collect::<Vec<_>>() | ||
}) | ||
.collect() | ||
} | ||
|
||
#[must_use] | ||
pub fn part1(input: &[Vec<u32>]) -> usize { | ||
input | ||
.iter() | ||
.filter(|row| { | ||
(row.iter().zip(row.iter().skip(1)).all(|(&a, &b)| a < b) | ||
|| row.iter().zip(row.iter().skip(1)).all(|(&a, &b)| a > b)) | ||
&& row | ||
.iter() | ||
.zip(row.iter().skip(1)) | ||
.all(|(&a, &b)| matches!(a.abs_diff(b), 1..4)) | ||
}) | ||
.count() | ||
} | ||
|
||
#[must_use] | ||
pub fn part2(input: &[Vec<u32>]) -> u32 { | ||
// todo!() | ||
0 | ||
} | ||
|
||
// For my input, the correct answer is: | ||
// Part 1: 407 | ||
// Part 2: |
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 |
---|---|---|
|
@@ -7,4 +7,5 @@ pub mod year2023 { | |
|
||
pub mod year2024 { | ||
mod day01_test; | ||
mod day02_test; | ||
} |
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,31 @@ | ||
use aoc::year2024::day02::*; | ||
|
||
const EXAMPLE_PART: &str = "\ | ||
7 6 4 2 1 | ||
1 2 7 8 9 | ||
9 7 6 2 1 | ||
1 3 2 4 5 | ||
8 6 4 4 1 | ||
1 3 6 7 9"; | ||
|
||
const EXAMPLE_PART1_CUSTOM: &str = "\ | ||
1 2 3 4 6 7 10 7 | ||
1 2 3"; | ||
|
||
#[test] | ||
fn test_sample_part1() { | ||
let input = parse(EXAMPLE_PART); | ||
assert_eq!(part1(&input), 2); | ||
} | ||
|
||
#[test] | ||
fn test_sample_part1_custom() { | ||
let input = parse(EXAMPLE_PART1_CUSTOM); | ||
assert_eq!(part1(&input), 0); | ||
} | ||
|
||
#[test] | ||
fn test_sample_part2() { | ||
let input = parse(EXAMPLE_PART); | ||
// assert_eq!(part2(&input), 31); | ||
} |