Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <math.h>
- using namespace std;
- int bf_ops_for_number(int x, int n) {
- if (x > n) {
- return 0;
- } else {
- return 1 + bf_ops_for_number(x + (x & -x), n);
- }
- }
- int main(int argc, char *argv[]) {
- double worst = 0;
- for(int n=1; n<65536; n++) {
- double sum = 0;
- double result;
- for(int j=1; j<=n; j++) {
- sum+=bf_ops_for_number(j, n);
- }
- result = sum/n;
- if (result > worst) {
- worst = result;
- printf("NEW WORST: %f for n=%d\n", result, n);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement