imk0tter
Aug 22nd, 2025
165
0
Never
4
This is comment for paste Recursive Kernel
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2.  
  3. void handle_open_port(unsigned int x);
  4. void handle_close_port(unsigned int x);
  5.  
  6. unsigned int * previous_x = 0;
  7.  
  8. void kernel_recursion(unsigned int x) {
  9.   unsigned int current_previous_x = *previous_x;
  10.   //printf("PREVIOUS_X: %u ADDRESS: %ld CURRENT_ADDRESS: %ld\n", current_previous_x, previous_x, (long)&x);
  11.   previous_x = &x;
  12.   if (x < current_previous_x) {
  13.     handle_open_port(x); ++x;
  14.     kernel_recursion(current_previous_x);--x;
  15.     handle_close_port(x);
  16.   } else if (current_previous_x < x) {
  17.     handle_open_port(current_previous_x);
  18.     kernel_recursion(current_previous_x + 1); --x;
  19.     handle_close_port(current_previous_x);
  20.   } else {
  21.     handle_open_port(current_previous_x);
  22.     handle_close_port(current_previous_x);
  23.   }
  24. }
  25. void kernel(unsigned int x) {
  26.   previous_x = &x;
  27.   kernel_recursion(0);
  28. }
  29.  
  30. int main() { kernel(10); }
  31.  
  32. void handle_open_port(unsigned int x) { printf("OPENING: %u\n", x); }
  33. void handle_close_port(unsigned int x) { printf("CLOSING: %u\n", x); }
Advertisement
Comments
  • imk0tter
    1 year
    # C++ 0.49 KB | 0 0
    1. #include <stdio.h>
    2.  
    3. void handle_open_port(unsigned int x);
    4. void handle_close_port(unsigned int x);
    5.  
    6. void kernel_recursion(unsigned int x, unsigned int y) {
    7.     handle_open_port(x);
    8.     if (x < y) kernel_recursion(x+1, y);
    9.     handle_close_port(x);
    10.  
    11. }
    12. void kernel(unsigned int y) {
    13.   kernel_recursion(0,y);
    14. }
    15.  
    16. int main() { kernel(100); }
    17.  
    18. void handle_open_port(unsigned int x) { printf("OPENING: %u\n", x); }
    19. void handle_close_port(unsigned int x) { printf("CLOSING: %u\n", x); }
  • imk0tter
    1 year
    # C++ 0.57 KB | 0 0
    1. #include <stdio.h>
    2.  
    3. void handle_open_port(unsigned int x);
    4. void handle_close_port(unsigned int x);
    5.  
    6. unsigned int y = 0;
    7. unsigned int z = 0;
    8.  
    9. void kernel_recursion(unsigned int x) {
    10.     y = z;
    11.     handle_open_port(x);
    12.     if (x < y) kernel_recursion(x + 1);
    13.     handle_close_port(x);
    14.  
    15. }
    16. void kernel(unsigned int limit) {
    17.     y = z = limit;
    18.     kernel_recursion(0);
    19.     y = z = 0;
    20. }
    21.  
    22. int main() { kernel(100); }
    23.  
    24. void handle_open_port(unsigned int x) { printf("OPENING: %u\n", x); }
    25. void handle_close_port(unsigned int x) { printf("CLOSING: %u\n", x); }
  • imk0tter
    1 year
    # C++ 0.57 KB | 0 0
    1. #include <stdio.h>
    2.  
    3. void handle_open_port(unsigned int x);
    4. void handle_close_port(unsigned int x);
    5.  
    6. unsigned int y = 0;
    7. unsigned int z = 0;
    8.  
    9. void kernel_recursion(unsigned int x) {
    10.     z = y;
    11.     handle_open_port(x);
    12.     if (x < y) kernel_recursion(x + 1);
    13.     handle_close_port(x);
    14.  
    15. }
    16. void kernel(unsigned int limit) {
    17.     y = z = limit;
    18.     kernel_recursion(0);
    19.     y = z = 0;
    20. }
    21.  
    22. int main() { kernel(100); }
    23.  
    24. void handle_open_port(unsigned int x) { printf("OPENING: %u\n", x); }
    25. void handle_close_port(unsigned int x) { printf("CLOSING: %u\n", x); }
  • imk0tter
    1 year
    # C++ 0.65 KB | 0 0
    1. #include <stdio.h>
    2.  
    3. void handle_open_port(unsigned int x);
    4. void handle_close_port(unsigned int x);
    5.  
    6. unsigned int y = 0;
    7.  
    8. void kernel_recursion(unsigned int x) {
    9.     handle_open_port(x);
    10.     if (x < y) kernel_recursion(x + 1);
    11.     handle_close_port(x);
    12.  
    13. }
    14. void kernel(unsigned int limit) {
    15.    
    16.     y = limit;
    17.     //TODO: Set y variable to have changed a maximum of 0 times
    18.     kernel_recursion(0);
    19.     //TODO: Unset y variable to have changed a maximum of 0 times
    20. }
    21.  
    22. int main() { kernel(100); }
    23.  
    24. void handle_open_port(unsigned int x) { printf("OPENING: %u\n", x); }
    25. void handle_close_port(unsigned int x) { printf("CLOSING: %u\n", x); }
Add Comment
Please, Sign In to add comment