-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path052.js
More file actions
28 lines (23 loc) · 655 Bytes
/
052.js
File metadata and controls
28 lines (23 loc) · 655 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// It can be seen that the number, 125874, and its double, 251748, contain
// exactly the same digits, but in a different order.
// Find the smallest positive integer, x, such that 2x, 3x, 4x, 5x, and 6x,
// contain the same digits.
function sameDigits(n) {
var original = (n+'').split('').sort().join();
var str;
for (var i = 2; i <= 6; i++) {
str = (n*i)+'';
if (str.split('').sort().join() !== original) {
return false;
}
}
return true;
}
function findMinSixfoldNumber() {
var i = 1;
while (!sameDigits(i)) {
i++;
}
return i;
}
console.log( findMinSixfoldNumber() );