Guest User

Untitled

a guest
May 23rd, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int cons(int n, int what)
  4. {
  5. int count = 0, max = 0;
  6. //printf("n: %i what: %i\n", n, what);
  7. for (int i = 0; i < 10; i++)
  8. {
  9. //printf("bit %i: %i\n", i, (n & (1 << i)));
  10. if ( !!(n & (1 << i)) == what )
  11. {
  12. ++count;
  13. //printf("bit %i == %i (count: %i)\n", i, what,
  14. // count);
  15. }
  16. else
  17. {
  18. //printf("bit %i != %i\n", i, what);
  19. max = (max > count)? max : count;
  20. count = 0;
  21. }
  22. }
  23. max = (max > count)? max : count;
  24. //printf("max: %i\n", max);
  25. return max;
  26. }
  27.  
  28. int main(int argc, char **argv)
  29. {
  30. int count = 0;
  31. for (int i = 0; i < 2048; i++)
  32. //for (int i = 31; i < 32; i++)
  33. {
  34. int o = cons(i, 1), z = cons(i, 0);
  35. //printf("%x: ones: %i zeros: %i\n", i, o, z);
  36. if (o >= 5 || z >= 5)
  37. count++;
  38. }
  39. printf("Count: %i\n", count);
  40. return 0;
  41. }
Add Comment
Please, Sign In to add comment