Optimized Largest Prime factor coding contract solver.

This commit is contained in:
danielyxie
2019-05-19 13:56:49 -07:00
parent 9f94d0838a
commit 6841f24932
2 changed files with 6 additions and 2 deletions

View File

@@ -0,0 +1,4 @@
/**
* Utility functions for calculating the maximum number of Hacknet upgrades the player
* can purchase for a Node with his/her current money
*/

View File

@@ -65,14 +65,14 @@ export const codingContractTypesMetadata: ICodingContractTypeMetadata[] = [
solver: (data: number, ans: string) => {
let fac: number = 2;
let n: number = data;
while (Math.sqrt(n) > fac-1) {
while (n > ((fac-1) * (fac-1))) {
while (n % fac === 0) {
n = Math.round(n / fac);
}
++fac;
}
return (n===1?(fac-1):n) === parseInt(ans, 10);
return (n===1 ? (fac-1) : n) === parseInt(ans, 10);
},
},
{