Created
July 26, 2012 20:46
-
-
Save crowding/3184404 to your computer and use it in GitHub Desktop.
The ruler function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <math.h> | |
#include <stdio.h> | |
/* The ruler function corresponds to the number of ones at the end of the | |
* binary representation of numbers. */ | |
int main(void) { | |
int i; | |
for (i = 1; i < 1000; i++) { | |
printf("%g ", log2( (i ^ (i-1)) + 1)); | |
if (i % 32 == 0) { | |
printf("\n"); | |
} | |
} | |
printf("\n"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment