Skip to content

Instantly share code, notes, and snippets.

@crowding
Created July 26, 2012 20:46
Show Gist options
  • Save crowding/3184404 to your computer and use it in GitHub Desktop.
Save crowding/3184404 to your computer and use it in GitHub Desktop.
The ruler function
#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