Updated for performance

This commit is contained in:
2020-06-18 01:30:28 -04:00
parent 7f7fdafa63
commit b89677ac54

View File

@@ -79,24 +79,10 @@ pub fn solve() -> Answer{
//Setup the list you are trying to find a path through //Setup the list you are trying to find a path through
let mut list = Vec::<Vec::<i32>>::new(); let mut list = Vec::<Vec::<i32>>::new();
for _ in 0..15{ for _ in 0..NUM_ROWS{
list.push(Vec::<i32>::new()); list.push(Vec::<i32>::new());
} }
list[0].push(75); setupList(&mut list);
list[1].extend_from_slice(&[95, 64]);
list[2].extend_from_slice(&[17, 47, 82]);
list[3].extend_from_slice(&[18, 35, 87, 10]);
list[4].extend_from_slice(&[20, 04, 82, 47, 65]);
list[5].extend_from_slice(&[19, 01, 23, 75, 03, 34]);
list[6].extend_from_slice(&[88, 02, 77, 73, 07, 63, 67]);
list[7].extend_from_slice(&[99, 65, 04, 28, 06, 16, 70, 92]);
list[8].extend_from_slice(&[41, 41, 26, 56, 83, 40, 80, 70, 33]);
list[9].extend_from_slice(&[41, 48, 72, 33, 47, 32, 37, 16, 94, 29]);
list[10].extend_from_slice(&[53, 71, 44, 65, 25, 43, 91, 52, 97, 51, 14]);
list[11].extend_from_slice(&[70, 11, 33, 28, 77, 73, 17, 78, 39, 68, 17, 57]);
list[12].extend_from_slice(&[91, 71, 52, 38, 17, 14, 91, 43, 58, 50, 27, 29, 48]);
list[13].extend_from_slice(&[63, 66, 04, 68, 89, 53, 67, 30, 73, 16, 69, 87, 40, 31]);
list[14].extend_from_slice(&[04, 62, 98, 27, 23, 9, 70, 98, 73, 93, 38, 53, 60, 04, 23]);
//Invert the list //Invert the list
invert(&mut list); invert(&mut list);
@@ -164,15 +150,35 @@ fn invert(list: &mut Vec::<Vec::<i32>>){
} }
//This function helps be removing th eelement that is the same as the minumum location //This function helps be removing th eelement that is the same as the minumum location
fn removeHelper(possiblePoints: &mut Vec<Location>, minLoc: Location){ fn removeHelper(possiblePoints: &mut Vec<Location>, minLoc: Location){
for loc in 0..possiblePoints.len(){ let mut loc = 0;
while(loc < possiblePoints.len()){
if(possiblePoints[loc] == minLoc){ if(possiblePoints[loc] == minLoc){
possiblePoints.remove(loc); possiblePoints.remove(loc);
break; }
else{
loc += 1;
} }
} }
} }
fn setupList(list: &mut Vec::<Vec::<i32>>){
list[0].push(75);
list[1].extend_from_slice(&[95, 64]);
list[2].extend_from_slice(&[17, 47, 82]);
list[3].extend_from_slice(&[18, 35, 87, 10]);
list[4].extend_from_slice(&[20, 04, 82, 47, 65]);
list[5].extend_from_slice(&[19, 01, 23, 75, 03, 34]);
list[6].extend_from_slice(&[88, 02, 77, 73, 07, 63, 67]);
list[7].extend_from_slice(&[99, 65, 04, 28, 06, 16, 70, 92]);
list[8].extend_from_slice(&[41, 41, 26, 56, 83, 40, 80, 70, 33]);
list[9].extend_from_slice(&[41, 48, 72, 33, 47, 32, 37, 16, 94, 29]);
list[10].extend_from_slice(&[53, 71, 44, 65, 25, 43, 91, 52, 97, 51, 14]);
list[11].extend_from_slice(&[70, 11, 33, 28, 77, 73, 17, 78, 39, 68, 17, 57]);
list[12].extend_from_slice(&[91, 71, 52, 38, 17, 14, 91, 43, 58, 50, 27, 29, 48]);
list[13].extend_from_slice(&[63, 66, 04, 68, 89, 53, 67, 30, 73, 16, 69, 87, 40, 31]);
list[14].extend_from_slice(&[04, 62, 98, 27, 23, 9, 70, 98, 73, 93, 38, 53, 60, 04, 23]);
}
/* Results: /* Results:
The value of the longest path is 1074 The value of the longest path is 1074
It took 195.800 microseconds to solve this problem It took 19.400 microseconds to solve this problem
*/ */