2022 rust matrix
This commit is contained in:
parent
93bc792894
commit
2afcd5263d
|
@ -98,7 +98,7 @@ fn solve2(data: &[Instruction]) -> String {
|
||||||
let row = (cycle - 1) / 40;
|
let row = (cycle - 1) / 40;
|
||||||
let col = (cycle - 1) % 40;
|
let col = (cycle - 1) % 40;
|
||||||
if register - 1 == col || register == col || register + 1 == col {
|
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)] = '#';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -49,21 +49,6 @@ impl<T> Matrix<T> {
|
||||||
self.array.iter()
|
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)> + '_ {
|
pub fn cell_indices(&self) -> impl Iterator<Item = (usize, usize)> + '_ {
|
||||||
(0..self.rows).into_iter()
|
(0..self.rows).into_iter()
|
||||||
.flat_map(|row| (0..self.cols).into_iter().map(move |col| (row, col)))
|
.flat_map(|row| (0..self.cols).into_iter().map(move |col| (row, col)))
|
||||||
|
|
Loading…
Reference in a new issue