Skip to content

Instantly share code, notes, and snippets.

@theoknock
Last active February 3, 2023 15:30
Show Gist options
  • Save theoknock/42d629d817f84ce1890f488ef401911f to your computer and use it in GitHub Desktop.
Save theoknock/42d629d817f84ce1890f488ef401911f to your computer and use it in GitHub Desktop.
Recursive block + Bitwise counter
- (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