Skip to content

Instantly share code, notes, and snippets.

@eugenegodun
Created November 11, 2017 17:31
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 eugenegodun/1e2551f35801d9aaf0a3b1cda5fb70dd to your computer and use it in GitHub Desktop.
Save eugenegodun/1e2551f35801d9aaf0a3b1cda5fb70dd to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<meta name="description" content="[https://projecteuler.net/problem=1]">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<script id="jsbin-javascript">
// https://projecteuler.net/problem=1
// The sum of all the multiples of 'a' or 'b' below 'n'.
"use strict";
function sumOfMultiplesXYBelowN(x, y, n) {
var result = 0;
function sum(x, y, n) {
var next = n - 1;
if (x < y && n <= x || x > y && n <= y) {
return result;
}
if (next % x === 0 || next % y === 0) {
result += next;
}
sum(x, y, next);
return result;
}
return sum(x, y, n);
}
console.log(sumOfMultiplesXYBelowN(3, 5, 1000));
</script>
<script id="jsbin-source-javascript" type="text/javascript">
// https://projecteuler.net/problem=1
// The sum of all the multiples of 'a' or 'b' below 'n'.
function sumOfMultiplesXYBelowN(x, y, n) {
let result = 0;
function sum(x, y, n) {
const next = n - 1;
if ((x < y && n <= x) || (x > y && n <= y) ) {
return result;
}
if (next % x === 0 || next % y === 0) {
result += next;
}
sum(x, y, next);
return result;
}
return sum(x, y, n);
}
console.log(sumOfMultiplesXYBelowN(3, 5, 1000));
</script></body>
</html>
// https://projecteuler.net/problem=1
// The sum of all the multiples of 'a' or 'b' below 'n'.
"use strict";
function sumOfMultiplesXYBelowN(x, y, n) {
var result = 0;
function sum(x, y, n) {
var next = n - 1;
if (x < y && n <= x || x > y && n <= y) {
return result;
}
if (next % x === 0 || next % y === 0) {
result += next;
}
sum(x, y, next);
return result;
}
return sum(x, y, n);
}
console.log(sumOfMultiplesXYBelowN(3, 5, 1000));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment