fork download
  1. #include <iostream>
  2. #include <stdint.h>
  3. #include <bitset>
  4.  
  5. using std::uint32_t;
  6. using std::uint64_t;
  7.  
  8. bool is_alternating(uint32_t x)
  9. {
  10. uint32_t y = x << 1;
  11. return (x & (y + (y | 3))) == x;
  12. }
  13.  
  14. int main() {
  15. for (uint64_t x = 0; x <= 0xFFFFFFFF; x++) {
  16. if (is_alternating(x)) {
  17. std::cout << std::bitset<32>(x) << "\n";
  18. }
  19. }
  20. return 0;
  21. }
Success #stdin #stdout 3.86s 5476KB
stdin
Standard input is empty
stdout
00000000000000000000000000000000
00000000000000000000000000000001
00000000000000000000000000000010
00000000000000000000000000000101
00000000000000000000000000001010
00000000000000000000000000010101
00000000000000000000000000101010
00000000000000000000000001010101
00000000000000000000000010101010
00000000000000000000000101010101
00000000000000000000001010101010
00000000000000000000010101010101
00000000000000000000101010101010
00000000000000000001010101010101
00000000000000000010101010101010
00000000000000000101010101010101
00000000000000001010101010101010
00000000000000010101010101010101
00000000000000101010101010101010
00000000000001010101010101010101
00000000000010101010101010101010
00000000000101010101010101010101
00000000001010101010101010101010
00000000010101010101010101010101
00000000101010101010101010101010
00000001010101010101010101010101
00000010101010101010101010101010
00000101010101010101010101010101
00001010101010101010101010101010
00010101010101010101010101010101
00101010101010101010101010101010
01010101010101010101010101010101
10101010101010101010101010101010