Skip to content

Instantly share code, notes, and snippets.

Created December 29, 2015 04:23
Show Gist options
  • Save anonymous/ff10799c503292b7a756 to your computer and use it in GitHub Desktop.
Save anonymous/ff10799c503292b7a756 to your computer and use it in GitHub Desktop.
https://repl.it/BarQ/1 created by Gereltuya
var totthree=0;
var totfive=0;
var a = 3983;
var dtotal=0;
for (var b=3; b<990; b++) {
if (b%3===0) {
totthree=totthree+b;
}
}
for (var c=5; c<990; c++) {
if (c%5===0) {
totfive=totfive+c;
}
}
for (var d=15; d<990; d++)
{ if (d%15===0) {
dtotal=dtotal+d;
}
}
console.log((a+totthree+totfive)-dtotal);
Native Browser JavaScript
>>> 232178
@gtaing1
Copy link

gtaing1 commented Dec 29, 2015

in this example, the problem were solved only contemplating till 990 and the rest were added manually (993; 995, 996, 999) and the result is 3983. In this example it is ( var a =3983).

  1. Loop b only counting multiples of 3 starting from 3 to 990 and sum result is named "totthree".
  2. Loop c only counting multiples of 5 starting from 5 to 990 and sum result is named to be "totfive".
  3. Loop d has taken care of duplication for the chance how many times 15 was counted twice starting from 15 to 990. and the sum result is named to dtotal would be considered as deduction to remove duplicated counts.

The total of the loops results came out to be 232178.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment