fanfannnmn

test_c.c

Sep 18th, 2021 (edited)
72
145 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <time.h>
  4. #define MAX_ATTEMPT 100
  5.  
  6. // compile with: 'gcc -o test_c test_c.c'
  7.  
  8. // this is a simple placeholder file that is intended to demonstrate the correct way to call the challenge binary
  9. // you will need to add logic to generate all input you wish to provide
  10. // You will additionally need to add your timing analysis around the "system()" call
  11. // This program will only be called ONCE, so all logic/loops you need to figure out the correct passcode in level1 should be contained in this single file
  12. int main()
  13. {
  14.     struct timeval {
  15.         long tv_sec;
  16.         long tv_usec;
  17.     };
  18.     struct timeval start, stop;
  19.     double diff = 0.0, avg_time = 0.0;
  20.     int counter = 0;
  21.  
  22.     // gussing until program return 0
  23.     while (counter < MAX_ATTEMPT) {
  24.         // execute program and timing
  25.         gettimeofday(&start, NULL);
  26.         system("./level1 9111");
  27.         gettimeofday(&stop, NULL);
  28.  
  29.         // calculate timing difference
  30.         diff = 1000000 * (stop.tv_sec - start.tv_sec) + stop.tv_usec - start.tv_usec;
  31.         avg_time += diff / 1000000.0;
  32.  
  33.         counter++;
  34.     }
  35.  
  36.     avg_time /= MAX_ATTEMPT;
  37.     printf("%f\n", avg_time);
  38.  
  39.     return 0;
  40. }
  41.  
RAW Paste Data