/* PROBLEM: Um número de 5 algarismos pode ser múltiplo da soma dos seus próprios algarismos ou não.
* Para todos os números de 5 algarismos existentes, que sejam múltiplos da soma dos seus algarismos,
* qual o quociente que mais vezes surge ? */
// VARIABLES
var digits = 5;
// CALCS
var q = {};
for(var i=0 ; i<Math.pow(10, digits) ; i++) {
var s = sumDigits(i);
if( i % s == 0 ) q[s] = q[s] ? ++q[s] : 1 ;
}
// PRINT RESULTS
console.log( q );
console.log( "Max: " + getMax(q) );
// FUNCTION SUM DIGITS
function sumDigits(number) {
var str = number.toString();
var sum = 0;
for (var i = 0; i < str.length; i++)
sum += parseInt(str.charAt(i), 10);
return sum;
}
// FUNCTION GET MAX RESULT
function getMax(arr) {
var max = 1;
for (var k in q)
if(arr[k] > arr[max]) max = k;
return max;
}
/*MINIFIED:
var digits = 5;
function s(e){var t=e.toString();var n=0;for(var r=0;r<t.length;r++)n+=parseInt(t.charAt(r),10);return n}function g(e){var t=1;for(var n in q)if(e[n]>e[t])t=n;return t}var q={};for(var i=0;i<Math.pow(10,digits);i++){var s=s(i);if(i%s==0)q[s]=q[s]?++q[s]:1}console.log(q);console.log("Max: "+g(q))*/
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.