Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int cons(int n, int what)
- {
- int count = 0, max = 0;
- //printf("n: %i what: %i\n", n, what);
- for (int i = 0; i < 10; i++)
- {
- //printf("bit %i: %i\n", i, (n & (1 << i)));
- if ( !!(n & (1 << i)) == what )
- {
- ++count;
- //printf("bit %i == %i (count: %i)\n", i, what,
- // count);
- }
- else
- {
- //printf("bit %i != %i\n", i, what);
- max = (max > count)? max : count;
- count = 0;
- }
- }
- max = (max > count)? max : count;
- //printf("max: %i\n", max);
- return max;
- }
- int main(int argc, char **argv)
- {
- int count = 0;
- for (int i = 0; i < 2048; i++)
- //for (int i = 31; i < 32; i++)
- {
- int o = cons(i, 1), z = cons(i, 0);
- //printf("%x: ones: %i zeros: %i\n", i, o, z);
- if (o >= 5 || z >= 5)
- count++;
- }
- printf("Count: %i\n", count);
- return 0;
- }
Add Comment
Please, Sign In to add comment