-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmultiples-by-permutations.js
More file actions
45 lines (36 loc) · 1.07 KB
/
multiples-by-permutations.js
File metadata and controls
45 lines (36 loc) · 1.07 KB
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/*
We have two consecutive integers k1 and k2, k2 = k1 + 1
We need to calculate the lowest strictly positive integer n, such that: the values nk1 and nk2 have the same digits but in different order.
E.g.# 1:
k1 = 100
k2 = 101
n = 8919
#Because 8919 * 100 = 891900
and 8919 * 101 = 900819
E.g.# 2:
k1 = 325
k2 = 326
n = 477
#Because 477 * 325 = 155025
and 477 * 326 = 155502
Your task is to prepare a function that will receive the value of k and outputs the value of n.
The examples given above will be:
find_lowest_int(100) === 8919
find_lowest_int(325) === 477
Features of the random tests
10 < k < 10.000.000.000.000.000 (For Python, Ruby and Haskell)
10 < k < 1.000.000.000 (For Javascript and D 1e9)
Enjoy it!!
*/
function findLowestInt(k) {
// your code here
var lowestInt;
let k2 = k + 1
for (let lowestInt = 1; lowestInt < 1000000001; lowestInt++){
let nk1 = k * lowestInt
let nk2 = k2 * lowestInt
nk1 = nk1.toString().split('').sort().join('')
nk2 = nk2.toString().split('').sort().join('')
if (nk1 == nk2) return lowestInt
}
}