Last active
September 25, 2015 16:07
-
-
Save netroy/948125 to your computer and use it in GitHub Desktop.
finding the largest product of 5 consecutive digits in an array/string of a rather large size
This file contains 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
x is some array of numbers |
This file contains 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
(apply max | |
(map #(reduce * %) | |
(for [i (range (count x))] | |
(take 5 (drop i x))))) |
This file contains 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
Math.max.apply(null, | |
x.map(function(v,i,a){ | |
return a.slice(i,i+5).reduce(function(p,c){ | |
return p*c; }); }) ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment