mirror of
https://github.com/TheAlgorithms/JavaScript.git
synced 2025-07-05 08:16:50 +08:00
@ -1,18 +1,18 @@
|
||||
// https://projecteuler.net/problem=3
|
||||
|
||||
export const largestPrime = (num = 600851475143) => {
|
||||
let newnumm = num
|
||||
let newnum = num
|
||||
let largestFact = 0
|
||||
let counter = 2
|
||||
while (counter * counter <= newnumm) {
|
||||
if (newnumm % counter === 0) {
|
||||
newnumm = newnumm / counter
|
||||
while (counter * counter <= newnum) {
|
||||
if (newnum % counter === 0) {
|
||||
newnum = newnum / counter
|
||||
} else {
|
||||
counter++
|
||||
}
|
||||
}
|
||||
if (newnumm > largestFact) {
|
||||
largestFact = newnumm
|
||||
if (newnum > largestFact) {
|
||||
largestFact = newnum
|
||||
}
|
||||
return largestFact
|
||||
}
|
||||
|
@ -2,11 +2,11 @@
|
||||
|
||||
const largestAdjacentNumber = (grid, consecutive) => {
|
||||
grid = grid.split('\n').join('')
|
||||
const splitedGrid = grid.split('\n')
|
||||
const splitGrid = grid.split('\n')
|
||||
let largestProd = 0
|
||||
|
||||
for (const row in splitedGrid) {
|
||||
const currentRow = splitedGrid[row].split('').map(x => Number(x))
|
||||
for (const row in splitGrid) {
|
||||
const currentRow = splitGrid[row].split('').map(x => Number(x))
|
||||
|
||||
for (let i = 0; i < currentRow.length - consecutive; i++) {
|
||||
const combine = currentRow.slice(i, i + consecutive)
|
||||
|
@ -14,7 +14,7 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* collect the abundant numbers, generate and store their sums with each other, and check for numbers not in the llst of sums, adds them and returns their sum.
|
||||
* collect the abundant numbers, generate and store their sums with each other, and check for numbers not in the list of sums, adds them and returns their sum.
|
||||
* @param {number} [n = 28123]
|
||||
* @returns {number}
|
||||
*/
|
||||
|
@ -40,7 +40,7 @@ function problem28 (dim) {
|
||||
* Third corner: i^2 - 2 * (i - 1)
|
||||
* Fourth corner: i^2 - 3 * (i - 1)
|
||||
*
|
||||
* Doing the sum of each corner and simplifing, we found that the result for each dimension is:
|
||||
* Doing the sum of each corner and simplifying, we found that the result for each dimension is:
|
||||
* sumDim = 4 * i^2 + 6 * (1 - i)
|
||||
*
|
||||
* In this case I skip the 1x1 dim matrix because is trivial, that's why I start in a 3x3 matrix
|
||||
|
Reference in New Issue
Block a user