From 8bc8a6c0c7443040ee92bac6fd7f01e198d862a8 Mon Sep 17 00:00:00 2001 From: Joel Therrien Date: Wed, 9 Sep 2020 15:47:32 -0700 Subject: [PATCH] Remove old commented out code. --- src/main.rs | 152 ---------------------------------------------------- 1 file changed, 152 deletions(-) diff --git a/src/main.rs b/src/main.rs index 3babea1..e60be64 100644 --- a/src/main.rs +++ b/src/main.rs @@ -287,155 +287,3 @@ fn main() { grid.print(); } - - - - -/* - - -/** - Only removes possibilities; does not add any - -*/ -fn calculate_and_remove_possibilities(grid: &mut Grid){ - - for r in 0..9{ - for c in 0..9 { - let cell = &*grid.get(r, c).unwrap(); - - let digit : u8 = match &*cell.borrow() { - CellValue::FIXED(digit) => {digit.clone()}, - CellValue::UNKNOWN(_) => {continue} - }; - - let (row, column, section) = grid.get_vectors_containing_coordinates(r, c).unwrap(); - let fun = |vec: &Vec>>| vec.iter().for_each(|x| remove_possibility(x.borrow(), &digit)); - - fun(row); - fun(column); - fun(section); - } - } -} - - - -fn remove_possibility(cell: &RefCell, to_remove: &u8){ - let borrowed_cell = cell.borrow(); - let value = &*borrowed_cell; - let existing_possibilities = match value { - CellValue::FIXED(_) => {return}, - CellValue::UNKNOWN(existing_possibilities) => existing_possibilities - }; - - let mut new_possibilities = existing_possibilities.clone(); - - match new_possibilities.binary_search(to_remove) { - Ok(index_remove) => {new_possibilities.remove(index_remove);}, - _ => {} - }; - - drop(borrowed_cell); - - let new_cell = CellValue::UNKNOWN(new_possibilities); - cell.replace(new_cell); -} - - -fn main() { - let mut grid = retrieve_grid(); - - calculate_and_remove_possibilities(&mut grid); - grid.print(); - -} - - - - -/** - For now this is a stub with a pre-programmed grid; later I'll add functionality to read a CSV file - */ -fn retrieve_grid() -> Grid { - let grid = Grid::new(); - - - grid.get(0, 4).unwrap().replace(CellValue::FIXED(8)); - grid.get(0, 5).unwrap().replace(CellValue::FIXED(5)); - grid.get(0, 6).unwrap().replace(CellValue::FIXED(6)); - - grid.get(2, 3).unwrap().replace(CellValue::FIXED(9)); - grid.get(2, 4).unwrap().replace(CellValue::FIXED(4)); - grid.get(2, 5).unwrap().replace(CellValue::FIXED(3)); - grid.get(2, 6).unwrap().replace(CellValue::FIXED(5)); - grid.get(2, 7).unwrap().replace(CellValue::FIXED(7)); - - grid.get(3, 0).unwrap().replace(CellValue::FIXED(8)); - grid.get(3, 2).unwrap().replace(CellValue::FIXED(2)); - grid.get(3, 3).unwrap().replace(CellValue::FIXED(6)); - grid.get(3, 4).unwrap().replace(CellValue::FIXED(7)); - grid.get(3, 5).unwrap().replace(CellValue::FIXED(4)); - grid.get(3, 6).unwrap().replace(CellValue::FIXED(9)); - - grid.get(4, 4).unwrap().replace(CellValue::FIXED(9)); - grid.get(4, 8).unwrap().replace(CellValue::FIXED(5)); - - grid.get(5, 1).unwrap().replace(CellValue::FIXED(6)); - grid.get(5, 6).unwrap().replace(CellValue::FIXED(2)); - - grid.get(6, 1).unwrap().replace(CellValue::FIXED(8)); - grid.get(6, 8).unwrap().replace(CellValue::FIXED(2)); - - grid.get(7, 3).unwrap().replace(CellValue::FIXED(7)); - grid.get(7, 5).unwrap().replace(CellValue::FIXED(6)); - grid.get(7, 7).unwrap().replace(CellValue::FIXED(5)); - grid.get(7, 8).unwrap().replace(CellValue::FIXED(4)); - - grid.get(8, 2).unwrap().replace(CellValue::FIXED(7)); - grid.get(8, 3).unwrap().replace(CellValue::FIXED(4)); - - /* - - grid.get_mut(0, 4).unwrap().0 = CellValue::FIXED(8); - grid.get_mut(0, 5).unwrap().0 = CellValue::FIXED(5); - grid.get_mut(0, 6).unwrap().0 = CellValue::FIXED(6); - - grid.get_mut(2, 3).unwrap().0 = CellValue::FIXED(9); - grid.get_mut(2, 4).unwrap().0 = CellValue::FIXED(4); - grid.get_mut(2, 5).unwrap().0 = CellValue::FIXED(3); - grid.get_mut(2, 6).unwrap().0 = CellValue::FIXED(5); - grid.get_mut(2, 7).unwrap().0 = CellValue::FIXED(7); - - grid.get_mut(3, 0).unwrap().0 = CellValue::FIXED(8); - grid.get_mut(3, 2).unwrap().0 = CellValue::FIXED(2); - grid.get_mut(3, 3).unwrap().0 = CellValue::FIXED(6); - grid.get_mut(3, 4).unwrap().0 = CellValue::FIXED(7); - grid.get_mut(3, 5).unwrap().0 = CellValue::FIXED(4); - grid.get_mut(3, 6).unwrap().0 = CellValue::FIXED(9); - - grid.get_mut(4, 4).unwrap().0 = CellValue::FIXED(9); - grid.get_mut(4, 8).unwrap().0 = CellValue::FIXED(5); - - grid.get_mut(5, 1).unwrap().0 = CellValue::FIXED(6); - grid.get_mut(5, 6).unwrap().0 = CellValue::FIXED(2); - - grid.get_mut(6, 1).unwrap().0 = CellValue::FIXED(8); - grid.get_mut(6, 8).unwrap().0 = CellValue::FIXED(2); - - grid.get_mut(7, 3).unwrap().0 = CellValue::FIXED(7); - grid.get_mut(7, 5).unwrap().0 = CellValue::FIXED(6); - grid.get_mut(7, 7).unwrap().0 = CellValue::FIXED(5); - grid.get_mut(7, 8).unwrap().0 = CellValue::FIXED(4); - - grid.get_mut(8, 2).unwrap().0 = CellValue::FIXED(7); - grid.get_mut(8, 3).unwrap().0 = CellValue::FIXED(4); - - */ - - - return grid; -} - - - */ \ No newline at end of file