Skip to content

Instantly share code, notes, and snippets.

@passcod
Last active December 14, 2015 00:38
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 passcod/4999822 to your computer and use it in GitHub Desktop.
Save passcod/4999822 to your computer and use it in GitHub Desktop.
var N = 1000,
digits = "",
sums = [],
i,l,n,sum,sub;
for (n = 1; n <= N; ++n) {
digits += Math.floor(Math.random() * 10);
}
for (n = 0; n <= (N-6); ++n) {
sub = digits.substr(n, 5);
sum = 0;
for (i = 0, l = sub.length; i < l; i++) {
sum += +sub[i];
}
sums.push([(sum<10?"0"+sum:sum), n, sub].join(":"));
}
print(sums.sort().pop());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment