1
0

day 10 part 1

This commit is contained in:
2024-12-10 06:46:53 +01:00
parent 1f4461a846
commit 0b6f6fd3ec
4 changed files with 138 additions and 2 deletions

View File

@@ -6,8 +6,8 @@ use std::{
/// A grid structure, indexed by (x, y) tuples. The top-left coordinate is (0, 0).
#[derive(Eq, PartialEq, Debug)]
pub struct Grid<T> {
content_width: i64,
content_height: i64,
pub content_width: i64,
pub content_height: i64,
content: Vec<T>,
}
@@ -40,6 +40,9 @@ impl<T> Grid<T> {
}
pub fn get(&self, c: Coord) -> Option<&T> {
if c.0 < 0 || c.0 >= self.content_width || c.1 < 0 || c.1 >= self.content_height {
return None;
}
let index = self.index_of(c);
if index < self.content.len() {
Some(&self.content[self.index_of(c)])