NODE
node
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
function A(K,distance,k,N,mintime)
{
distance+=N;
console.log(`moves to ${distance}`)
mintime+=1
if(distance<K)
B(K,distance,k,N,mintime);
else{
console.log(`Destination reached at ${distance}`);
console.log(`Number of moves taken:${mintime}`)
}
}
function B(K,distance,k,N,mintime)
{
distance+=k;
console.log(`drops to ${distance}`)
A(K,distance,k,N,mintime);
}
let N=5;
let k=-3;
let destination=250;
let distance=0;
let mintime=0;
console.log(`A drunkard walking in a narrow lane takes 5 steps forward and 3 steps backward in 1 move,followed again by 5 steps forward and 3 steps backward, and so on. Let's find out the minimum moves he takes to reach the destination.\n`);
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run