Skip to content

Instantly share code, notes, and snippets.

@netroy
Last active September 25, 2015 16:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save netroy/948125 to your computer and use it in GitHub Desktop.
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
x is some array of numbers
(apply max
(map #(reduce * %)
(for [i (range (count x))]
(take 5 (drop i x)))))
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