Live data from Hacker News

Beating C with one line of Brainfuck

kiwec.net

1–10 of 91 posts

Re: Beating C with one line of Brainfuck

#6
Generated C:

  #include 
  
  char mem[30000] = {  };
  
  #define OUTPUTS 0
  char outputs[OUTPUTS] = {  };
  
  int main() {
      char* ptr = mem + 0;
      fwrite(outputs, sizeof(char), OUTPUTS, stdout);
  
      ptr[2] = getchar();
      ++ptr[2];
      while (ptr[2]) {
          ptr[2] -= 11;
          while (ptr[2]) {
              ptr[2] -= 22;
              while (ptr[2]) {
                  ++ptr[3];
                  --ptr[1];
                  while (ptr[1]) {
                      ++*ptr;
                      ++ptr[1];
                  }
                  ptr[2] = 0;
              }
              ptr[2] = 0;
          }
          ptr[1] = 0;
          ptr[1] += ptr[3] * 1;
          ptr[3] = 0;
          ptr[2] = getchar();
          ++ptr[2];
      }
      ptr[1] = 0;
      ptr[3] += *ptr * 1;
      ptr[2] += *ptr * 1;
      *ptr = 0;
      *ptr += ptr[3] * 1;
      ptr[3] = 0;
      ++ptr[1];
      while (ptr[2]) {
          --ptr[1];
          while (ptr[2]) {
              ptr[3] += 10;
              while (ptr[2]) {
                  --ptr[2];
                  --ptr[3];
                  while (ptr[3]) {
                      ++ptr[4];
                      ptr += 3;
                  }
                  while (ptr[4]) {
                      ++ptr[4];
                      ptr[3] += ptr[4] * 1;
                      ptr[4] = 0;
                      ++ptr[5];
                      ptr += 3;
                  }
                  ptr -= 3;
              }
              ptr[3] = 8;
              ptr[2] += ptr[3] * 6;
              ptr[3] = 0;
              ptr[2] += ptr[4] * 1;
              ptr[4] = 0;
              ptr[3] += ptr[5] * 1;
              ptr[5] = 0;
              ++ptr;
          }
          ++ptr;
      }
      while (ptr[1]) {
          --ptr[1];
          ptr[3] += 8;
          ptr[2] += ptr[3] * 6;
          ptr[3] = 0;
          ptr += 2;
      }
      while (ptr[0]) {
          putchar(ptr[0]);
          *ptr = 0;
          --ptr;
      }
      ptr[1] += 10;
      putchar(ptr[1]);
  
      return 0;
  }

Re: Beating C with one line of Brainfuck

#7
post #6

Generated C: #include char mem[30000] = { }; #define OUTPUTS 0 char outputs[OUTPUTS] = { }; int main() { char* ptr = mem + 0; fwrite(outputs, sizeof(char), OUTPUTS, stdout); ptr[2] = getchar(); ++ptr[2]; while (ptr[2]) { ptr[2] -= 11; while (ptr[2]) { ptr[2] -= 22; while (ptr[2]) { ++ptr[3]; --ptr[1]; while (ptr[1]) { ++*ptr; ++ptr[1]; } ptr[2] = 0; } ptr[2] = 0; } ptr[1] = 0; ptr[1] += ptr[3] * 1; ptr[3] = 0; ptr[2]…

my eyes!

Re: Beating C with one line of Brainfuck

#10

I wonder if Brainfuck wins by his 100th of a second since he already called a program with words.txt, and therefore it was already loaded into memory, thus saving just a slice of time, as it would already be in the cache.

Could also be that their version of wc is doing Unicode-aware counting by default; it could be a lot faster with LANG=C set in the environment.

https://unix.stackexchange.com/a/96580

Post reply on HN