Created
June 26, 2016 13:00
-
-
Save ooade/5250a0b7f27f0cf94b10f34ed46e4df4 to your computer and use it in GitHub Desktop.
ProjectEuler 11 JavaScript Solution
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Placed On Hackerrank */ | |
function processData(input) { | |
let grid = []; | |
for (let num of input.split('\n')) { | |
grid.push(num.split(' ')); | |
} | |
let g = 0; | |
for (let i = 0; i < 20; i++) { | |
for (let j = 0; j < 20; j++) { | |
//left | |
let product = eval(grid[i][j] * grid[+i][+j - 1] * grid[+i][+j - 2] * grid[+i][+j - 3]); | |
if (product > g) { | |
g = product; | |
} | |
//right | |
product = eval(grid[i][j] * grid[+i][+j + 1] * grid[+i][+j + 2] * grid[+i][+j + 3]); | |
if (product > g) { | |
g = product; | |
} | |
} | |
} | |
for (let i = 0; i < 17; i++) { | |
for (let j = 0; j < 20; j++) { | |
//diagonal left | |
let product = eval(grid[i][j] * grid[+i + 1][+j - 1] * grid[+i + 2][+j - 2] * grid[+i + 3][+j - 3]); | |
if (product > g) { | |
g = product; | |
} | |
//diagonal right | |
product = eval(grid[i][j] * grid[+i + 1][+j + 1] * grid[+i + 2][+j + 2] * grid[+i + 3][+j + 3]); | |
if (product > g) { | |
g = product; | |
} | |
} | |
} | |
console.log(g); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment