mirror of
https://github.com/RussellChamp/advent-of-code-2025-cursor.git
synced 2026-10-27 23:52:34 +00:00
Add Day 9 Part 1 solution - find largest rectangle from red tiles
This commit is contained in:
1 parent
b067baac3d
commit
cb01d29665
3 files changed
+66
-1
No files matched your search
@@ -19,8 +19,9 @@ Solutions for [Advent of Code](https://adventofcode.com/) in [Rust](https://www.
|
|||||||
| [Day 6](./src/bin/06.rs) | `118.7µs` | `124.8µs` |
|
| [Day 6](./src/bin/06.rs) | `118.7µs` | `124.8µs` |
|
||||||
| [Day 7](./src/bin/07.rs) | `91.8µs` | `72.4µs` |
|
| [Day 7](./src/bin/07.rs) | `91.8µs` | `72.4µs` |
|
||||||
| [Day 8](./src/bin/08.rs) | `11.2ms` | `9.8ms` |
|
| [Day 8](./src/bin/08.rs) | `11.2ms` | `9.8ms` |
|
||||||
|
| [Day 9](./src/bin/09.rs) | `114.1µs` | `-` |
|
||||||
|
|
||||||
**Total: 23.40ms**
|
**Total: 23.51ms**
|
||||||
<!--- benchmarking table --->
|
<!--- benchmarking table --->
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
7,1
|
||||||
|
11,1
|
||||||
|
11,7
|
||||||
|
9,7
|
||||||
|
9,5
|
||||||
|
2,5
|
||||||
|
2,3
|
||||||
|
7,3
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
advent_of_code::solution!(9);
|
||||||
|
|
||||||
|
use itertools::Itertools;
|
||||||
|
|
||||||
|
fn parse_coords(input: &str) -> Vec<(i64, i64)> {
|
||||||
|
input
|
||||||
|
.lines()
|
||||||
|
.filter_map(|line| {
|
||||||
|
let line = line.trim();
|
||||||
|
if line.is_empty() {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
let (x, y) = line.split_once(',')?;
|
||||||
|
Some((x.trim().parse().ok()?, y.trim().parse().ok()?))
|
||||||
|
})
|
||||||
|
.collect()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn rectangle_area(p1: (i64, i64), p2: (i64, i64)) -> u64 {
|
||||||
|
let width = (p2.0 - p1.0).abs() + 1;
|
||||||
|
let height = (p2.1 - p1.1).abs() + 1;
|
||||||
|
(width * height) as u64
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn part_one(input: &str) -> Option<u64> {
|
||||||
|
let coords = parse_coords(input);
|
||||||
|
|
||||||
|
coords
|
||||||
|
.iter()
|
||||||
|
.tuple_combinations()
|
||||||
|
.map(|(&p1, &p2)| rectangle_area(p1, p2))
|
||||||
|
.max()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn part_two(input: &str) -> Option<u64> {
|
||||||
|
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, Some(50));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_part_two() {
|
||||||
|
let result = part_two(&advent_of_code::template::read_file("examples", DAY));
|
||||||
|
assert_eq!(result, None);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user