Last active
February 3, 2023 15:30
-
-
Save theoknock/42d629d817f84ce1890f488ef401911f to your computer and use it in GitHub Desktop.
Recursive block + Bitwise counter
This file contains hidden or 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
- (void)recursive_block { | |
unsigned long (^recursive_block)(int); | |
unsigned long (^ const (* restrict recursive_block_t))(int) = &recursive_block; | |
__block unsigned long iterations = 30; | |
iterations = ~(1 << (iterations + 1)); | |
__block unsigned long iteration; | |
recursive_block = ^ (void(^print_block)(int, int)) { | |
return ^ unsigned long (int count) { | |
iteration = floor(log2(iterations)); | |
iterations >>= 1; | |
print_block(count++, (int)iteration); | |
return (iterations & 1) && (*recursive_block_t)(count); | |
}; | |
}(^ (int l, int i) { | |
printf("count == %d\t\titeration == %d\n", l, i); | |
}); | |
recursive_block(0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment