SHARE
TWEET

RANDOM VS BRUTEFORCE

a guest Sep 18th, 2019 90 in 334 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <math.h>
  3. #include <cstdlib>
  4. #include <stdlib.h>
  5. #include <time.h>
  6. using namespace std;
  7.  
  8. int main()
  9. {  
  10.     srand(time(0));
  11.     double S,m,n;
  12.     cout<<"S = "; cin>>S;
  13.     cout<<"m = "; cin>>m;
  14.     cout<<"n = "; cin>>n;
  15. //  double r = p/100;
  16.     double r = 0.001;
  17.     double new_m = 0;
  18.     int iter1 = 0;
  19.     while (new_m - m < 0.000001){
  20.         new_m = (S*r*pow((1+r),n)) / (12*(pow((1+r),n)-1));
  21.         r += 0.0001;
  22.         iter1 ++;
  23.     }
  24.     cout<<"new_m = "<<new_m<<endl;
  25.     cout<<"p = "<<r*100<<endl;
  26.     cout<<r<<endl;
  27.     cout<<"iter1 = "<<iter1<<endl;
  28.     cout<<"----------------------"<<endl;
  29.    
  30.     new_m = 0;
  31.     int iter2 = 0;
  32.     for(int i = 0;i< iter1;) {
  33.         r = rand();
  34.         while (r< 10001)
  35.             r = r*10;
  36.         if (r == 0)
  37.             r = 0.01;
  38.         r = abs(0.0001 * (int(r) % 10001));
  39.         //r = 0.2998;
  40.         if (0.298 < r && r < 0.30)
  41.             cout<<"VERY CLOSE!"<< r <<endl;
  42.         new_m = (S*r*pow((1+r),n)) / (12*(pow((1+r),n)-1));
  43.         iter2 ++;
  44.         if (abs(new_m - m) < 0.1){
  45.             cout<<"new_m = "<<new_m<<endl;
  46.             cout<<"p = "<<r*100<<endl;
  47.             cout<<"iter2 = "<<iter2;
  48.             return 0;
  49.         }
  50.     }
  51.    
  52.    
  53.     return 0;
  54. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top