2022 rust matrix

This commit is contained in:
Maciej Jur 2022-12-10 16:45:28 +01:00
parent 93bc792894
commit 2afcd5263d
2 changed files with 1 additions and 16 deletions

View file

@ -98,7 +98,7 @@ fn solve2(data: &[Instruction]) -> String {
let row = (cycle - 1) / 40;
let col = (cycle - 1) % 40;
if register - 1 == col || register == col || register + 1 == col {
crt.set_at(row as usize, col as usize, '#');
crt[(row as usize, col as usize)] = '#';
}
}

View file

@ -49,21 +49,6 @@ impl<T> Matrix<T> {
self.array.iter()
}
pub fn get_at(&self, row: usize, col: usize) -> &T {
let offset = self.get_offset(row, col);
&self.array[offset]
}
pub fn get_mut_at(&mut self, row: usize, col: usize) -> &mut T {
let offset = self.get_offset(row, col);
&mut self.array[offset]
}
pub fn set_at(&mut self, row: usize, col: usize, value: T) {
let offset = self.get_offset(row, col);
self.array[offset] = value;
}
pub fn cell_indices(&self) -> impl Iterator<Item = (usize, usize)> + '_ {
(0..self.rows).into_iter()
.flat_map(|row| (0..self.cols).into_iter().map(move |col| (row, col)))