pub fn solve(&self) -> Solution {
		let m_len = self.seq_x.len() + 1;
		let n_len = self.seq_y.len() + 1;

		// scoring matrix
		let m = self.matrix();

		// path construction
		let mut paths: Vec<Vec<Coordinates>> = vec![vec![(0, 0)]];
		for i in 0..m_len {
			for j in 0..n_len {
				if (i, j) == (0, 0) {
					continue;
				}

				// Iterate over a copy since we are mutating paths.
				for (idx, mut p) in paths.clone().into_iter().enumerate() {
					let last = p.last().unwrap();

					if i >= last.0 && j >= last.1 {
						let step_x = j - last.1;
						let step_y = i - last.0;

						let add = || {
							p.push((i, j));
							paths.push(p);
						};

						// Add the candidate path if it's connected, i.e., right, down, or diagonal.
						match (step_x, step_y) {
							(0, 1) => add(),
							(1, 0) => add(),
							(1, 1) => add(),
							(_, _) => (),
						}

						// positional path elimination
						let mut elim = || {
							paths.remove(idx);
						};
						if step_y == 1 {
							match (n_len - j, step_x) {
								(0, 0) => elim(), // end of column
								(1, 1) => elim(), // penultimate column
								(_, 2) => elim(), // paths have been constructed
								(_, _) => (),
							}
						}
					}
				}
			}
		}
		println!("Total number of paths: {}", paths.len());
		paths.retain(|p| {
			let last = p.last().unwrap();
			last.0 == m_len - 1 && last.1 == n_len - 1
		});
		println!("Total number of complete paths: {}", paths.len());
		let top_score = m[[m_len - 1, n_len - 1]];
		let mut optimal_paths = Vec::<Vec<Coordinates>>::new();
		for p in paths {
			if self.traceback(&p) == top_score {
				optimal_paths.push(p);
			};
		}
		Solution::new(optimal_paths, top_score, m)
	}
// This is far from optimal.
// It works like this:
// 1. Construct the matrix.
// 2. Find possible paths.
// 3. Traceback to find optimal paths.
//
// In step 2, there is some elimination of paths based on position.
This is far from optimal.
It works like this:
1. Construct the matrix.
2. Find possible paths.
3. Traceback to find optimal paths.

In step 2, there is some elimination of paths based on position.
This is far from optimal . It works like this : 1 . Construct the matrix . 2 . Find possible paths . 3 . Traceback to find optimal paths . In step 2 there is some elimination of paths based on position .
pub fn solve(&self) -> Solution {
		let m_len = self.seq_x.len() + 1;
		let n_len = self.seq_y.len() + 1;
		// scoring matrix
		let m = self.matrix();
		// path construction
		let mut paths: Vec<Vec<Coordinates>> = vec![vec![(0, 0)]];
		for i in 0..m_len {
			for j in 0..n_len {
				if (i, j) == (0, 0) {
					continue;
				}
				// Iterate over a copy since we are mutating paths.
				for (idx, mut p) in paths.clone().into_iter().enumerate() {
					let last = p.last().unwrap();
					if i >= last.0 && j >= last.1 {
						let step_x = j - last.1;
						let step_y = i - last.0;
						let add = || {
							p.push((i, j));
							paths.push(p);
						};
						// Add the candidate path if it's connected, i.e., right, down, or diagonal.
						match (step_x, step_y) {
							(0, 1) => add(),
							(1, 0) => add(),
							(1, 1) => add(),
							(_, _) => (),
						}
						// positional path elimination
						let mut elim = || {
							paths.remove(idx);
						};
						if step_y == 1 {
							match (n_len - j, step_x) {
								(0, 0) => elim(), // end of column
								(1, 1) => elim(), // penultimate column
								(_, 2) => elim(), // paths have been constructed
								(_, _) => (),
							}
						}
					}
				}
			}
		}
		println!("Total number of paths: {}", paths.len());
		paths.retain(|p| {
			let last = p.last().unwrap();
			last.0 == m_len - 1 && last.1 == n_len - 1
		});
		println!("Total number of complete paths: {}", paths.len());
		let top_score = m[[m_len - 1, n_len - 1]];
		let mut optimal_paths = Vec::<Vec<Coordinates>>::new();
		for p in paths {
			if self.traceback(&p) == top_score {
				optimal_paths.push(p);
			};
		}
		Solution::new(optimal_paths, top_score, m)
	}
pub fn solve ( & self ) -> Solution { let m_len = self . seq_x . len ( ) + 1 ; let n_len = self . seq_y . len ( ) + 1 ; // scoring matrix let m = self . matrix ( ) ; // path construction let mut paths : Vec < Vec < Coordinates > > = vec ! [ vec [ ( 0 0 ) ] ] ; for i in 0 .. m_len { for j in 0 .. n_len { if ( i , j ) == ( 0 , 0 ) { continue ; } // Iterate over a copy since we are mutating paths. for ( idx , mut p ) in paths . clone ( ) . into_iter ( ) . enumerate ( ) { let last = p . last ( ) . unwrap ( ) ; if i >= last . 0 && j >= last . 1 { let step_x = j - last . 1 ; let step_y = i - last . 0 ; let add = | | { p . push ( ( i , j ) ) ; paths . push ( p ) ; } ; // Add the candidate path if it's connected, i.e., right, down, or diagonal. match ( step_x , step_y ) { ( 0 , 1 ) => add ( ) , ( 1 , 0 ) => add ( ) , ( 1 , 1 ) => add ( ) , ( _ , _ ) => ( ) , } // positional path elimination let mut elim = | | { paths . remove ( idx ) ; } ; if step_y == 1 { match ( n_len - j , step_x ) { ( 0 , 0 ) => elim ( ) , // end of column ( 1 , 1 ) => elim ( ) , // penultimate column ( _ , 2 ) => elim ( ) , // paths have been constructed ( _ , _ ) => ( ) , } } } } } } println ! ( " " paths len ( ) ) ; paths . retain ( | p | { let last = p . last ( ) . unwrap ( ) ; last . 0 == m_len - 1 && last . 1 == n_len - 1 } ) ; println ! ( " " paths len ( ) ) ; let top_score = m [ [ m_len - 1 , n_len - 1 ] ] ; let mut optimal_paths = Vec :: < Vec < Coordinates > > :: new ( ) ; for p in paths { if self . traceback ( & p ) == top_score { optimal_paths . push ( p ) ; } ; } Solution :: new ( optimal_paths , top_score , m ) }
This is far from optimal.
This is far from optimal .
&self
&self