I am doing the stress testing for the following problem of my function myFunc()
.
There is a stone bridge connecting two cities. The first stone starting from one city is having 1 inscribed on it, and the last stone is on another city side. Each subsequent stone has two consecutive numbers on it except the last stone which may have one or two numbers inscribed on it depending on the value of N. Stones may be aligned as 1, (2, 3), (4, 5), (6, 7)... N.
You are given a number N representing the last number on the last stone; and a number X. The task is to find the minimum number of jumps you need from either the first city side or the second city side to reach the stone that has X inscribed on it. Note: Jumping on the first stone will be counted as 0 jumps.
Example: Input: 2 10 3 5 1
Output: 1 0
Explanation: Testcase 1: Stone alignment for N = 10 is as follows: 1, (2, 3), (4, 5), (6, 7), (8, 9), 10 To jump on X = 3, you only need one jump (since first stone jump will not be counted) from First city side, and 4 jumps from the second side. So the minimum of 1 and 4 is 1.
Testcase 2: Stone alignment for N = 5 is as follows: 1, (2, 3), (4, 5) To jump on X = 1, you only need zero jumps (since first stone jump will not be counted) from First city side, and 2 jumps from the second city side. So the minimum of 0 and 2 is 0.
#include <iostream>
#include <algorithm>
#include <ctime>
using namespace std;
int myFunc(int n, int p) {
return p / 2;
}
int findJumps(int n, int p){
return min(X /2, (N / 2) - (X / 2));
}
int main() {
int n, x;
srand(time(0));
while(true) {
n = rand() % 40 + 1; // I want n to be always greater than x
x = rand() % 40 + 1;
if(myFunc(n, x) != findJumps(n, x)) {
cout << n << " " << x;
break;
}
else cout << n << " " << x;
cout << endl;
}
return 0;
}