4 deleted 201 characters in body
source | link

C, 355 347 300300 294 chars

Edit: realized I don't need feof()

Edit: Saved 47 chars! Removed the Sleep, got rid of almost all braces, combined a lot of operations.

Edit: Last one today, since I broke 300 chars. Changed printf to puts, found a cute little optimization with the first comparison.

C does not lend itself well to this sort of problem, but hey, golfing it is fun. This is a pretty brute-force implementation, but I wanted to see how far I could golf it up.

Input is a text file named i. It contains a representation of the starting state, with * for copper, + for electron head, - for electron tail, spaces for empty cells. I'm using the XOR gate from the wiki page for testing.

   ****-+**
  +        ******
   -*******      *
                ****
                *  *****
                ****
   ********      *
  +        ******
   -****+-*

char*p,t[42][42],s[42][42];
main(i,r,c,n,j)
{
  for(p=fopen("i","r");fgets(s[i++]+1,40,p););

  for(;;getch(),memcpy(s,t,1764))
    for(j=1;j<41;printfj=1;j<41;puts(s[j++]+1))
      for(i=1;i<41;)
      {
        p=t[j]+i;
        r=*p=s[j][i++];
        if(r==43)r=s[j][i++];
          *p=45;*p=r==43?45:r;
        if(r==45)
          *p=42;
        if(r==42)
          for(r=-1,n=0;r<2;++r,*p=n&&n<3?43:42)
            for(c=-2;c<1;)
              n+=s[j+r][i+c++]==43;
      }
}

Whitespace removed:

char*p,t[42][42],s[42][42];main(i,r,c,n,j){for(p=fopen("i","r");fgets(s[i++]+1,40,p););for(;;getch(),memcpy(s,t,1764))for(j=1;j<41;printf(s[j++]+1))for(i=1;i<41;){p=t[j]+i;r=*p=s[j][i++];if(r==43)*p=45;if(r==45)*p=42;if(r==42)for(r=-1,n=0;r<2;++r,*p=n&&n<3?43:42)for(c=-2;c<1;)n+=s[j+r][i+c++]==43;}}

C, 355 347 300 chars

Edit: realized I don't need feof()

Edit: Saved 47 chars! Removed the Sleep, got rid of almost all braces, combined a lot of operations.

C does not lend itself well to this sort of problem, but hey, golfing it is fun. This is a pretty brute-force implementation, but I wanted to see how far I could golf it up.

Input is a text file named i. It contains a representation of the starting state, with * for copper, + for electron head, - for electron tail, spaces for empty cells. I'm using the XOR gate from the wiki page for testing.

   ****-+**
  +        ******
   -*******      *
                ****
                *  *****
                ****
   ********      *
  +        ******
   -****+-*

char*p,t[42][42],s[42][42];
main(i,r,c,n,j)
{
  for(p=fopen("i","r");fgets(s[i++]+1,40,p););

  for(;;getch(),memcpy(s,t,1764))
    for(j=1;j<41;printf(s[j++]+1))
      for(i=1;i<41;)
      {
        p=t[j]+i;
        r=*p=s[j][i++];
        if(r==43)
          *p=45;
        if(r==45)
          *p=42;
        if(r==42)
          for(r=-1,n=0;r<2;++r,*p=n&&n<3?43:42)
            for(c=-2;c<1;)
              n+=s[j+r][i+c++]==43;
      }
}

Whitespace removed:

char*p,t[42][42],s[42][42];main(i,r,c,n,j){for(p=fopen("i","r");fgets(s[i++]+1,40,p););for(;;getch(),memcpy(s,t,1764))for(j=1;j<41;printf(s[j++]+1))for(i=1;i<41;){p=t[j]+i;r=*p=s[j][i++];if(r==43)*p=45;if(r==45)*p=42;if(r==42)for(r=-1,n=0;r<2;++r,*p=n&&n<3?43:42)for(c=-2;c<1;)n+=s[j+r][i+c++]==43;}}

C, 355 347 300 294 chars

Edit: realized I don't need feof()

Edit: Saved 47 chars! Removed the Sleep, got rid of almost all braces, combined a lot of operations.

Edit: Last one today, since I broke 300 chars. Changed printf to puts, found a cute little optimization with the first comparison.

C does not lend itself well to this sort of problem, but hey, golfing it is fun. This is a pretty brute-force implementation, but I wanted to see how far I could golf it up.

Input is a text file named i. It contains a representation of the starting state, with * for copper, + for electron head, - for electron tail, spaces for empty cells. I'm using the XOR gate from the wiki page for testing.

   ****-+**
  +        ******
   -*******      *
                ****
                *  *****
                ****
   ********      *
  +        ******
   -****+-*

char*p,t[42][42],s[42][42];
main(i,r,c,n,j)
{
  for(p=fopen("i","r");fgets(s[i++]+1,40,p););

  for(;;getch(),memcpy(s,t,1764))
    for(j=1;j<41;puts(s[j++]+1))
      for(i=1;i<41;)
      {
        p=t[j]+i;
        r=s[j][i++];
        *p=r==43?45:r;
        if(r==45)
          *p=42;
        if(r==42)
          for(r=-1,n=0;r<2;++r,*p=n&&n<3?43:42)
            for(c=-2;c<1;)
              n+=s[j+r][i+c++]==43;
      }
}
3 deleted 103 characters in body
source | link

C, 355 347347 300 chars

Edit: Saved 47 chars! Removed the Sleep, got rid of almost all braces, combined a lot of operations.

C does not lend itself well to this sort of problem, but hey, golfing it is fun. This is a pretty brute-force implementation, but I wanted to see how far I could golf it up. There's also no built-in sleep function in the C libraries, so I had to #include <windows.h> to get Sleep() to slow down the display.

#include <windows.h>
char*p,t[42][42],s[42][42];
main(i,r,c,n,j,m)
{
  char*p,t[42][42],s[42][42]={0};

  int*f=fopenfor(p=fopen("i","r");
  while(fgets;fgets(s[i++]+1,40,fp););

  for(;;;;getch()
  {
    for,memcpy(j=1;j<41;++js,t,1764)
    {)
      printffor(s[j]+1j=1;j<41;printf(s[j++]+1);)
      for(i=1;i<41;++ii=1;i<41;)
      {
        p=&t[j][i];p=t[j]+i;
        m=*p=s[j][i];r=*p=s[j][i++];
        if(m==43r==43)
          *p=45;
        if(m==45r==45)
          *p=42;
        if(m==42r==42)
        {
          for(r=-1,n=0;r<2;++r,*p=n&&n<3?43:42)
            for(c=-1;c<2;2;c<1;)
              n+=s[j+r][i+c++]==43;
          if(n&&n<3)*p=43;
        }
      }
    }
    memcpy(s,t,42*42);
    Sleep(200);
  }
}
#include <windows.h>
mainchar*p,t[42][42],s[42][42];main(i,r,c,n,j,m){char*p,t[42][42],s[42][42]={0};int*f=fopenfor(p=fopen("i","r");while(fgets;fgets(s[i++]+1,40,fp););for(;;;;getch(){for,memcpy(j=1;j<41;++js,t,1764){printf)for(s[j]+1j=1;j<41;printf(s[j++]+1);for)for(i=1;i<41;++ii=1;i<41;){p=&t[j][i];m=*p=s[j][i];ifp=t[j]+i;r=*p=s[j][i++];if(m==43r==43)*p=45;if(m==45r==45)*p=42;if(m==42r==42){for(r=-1,n=0;r<2;++r,*p=n&&n<3?43:42)for(c=-1;c<2;)n+=s[j+r][i+c++]==43;if(n&&n<3)*p=43;}}}memcpy(s,t,42*42);Sleep(2002;c<1;);n+=s[j+r][i+c++]==43;}}

C, 355 347 chars

C does not lend itself well to this sort of problem, but hey, golfing it is fun. This is a pretty brute-force implementation, but I wanted to see how far I could golf it up. There's also no built-in sleep function in the C libraries, so I had to #include <windows.h> to get Sleep() to slow down the display.

#include <windows.h>

main(i,r,c,n,j,m)
{
  char*p,t[42][42],s[42][42]={0};

  int*f=fopen("i","r");
  while(fgets(s[i++]+1,40,f));

  for(;;)
  {
    for(j=1;j<41;++j)
    {
      printf(s[j]+1);
      for(i=1;i<41;++i)
      {
        p=&t[j][i];
        m=*p=s[j][i];
        if(m==43)
          *p=45;
        if(m==45)
          *p=42;
        if(m==42)
        {
          for(r=-1,n=0;r<2;++r)
            for(c=-1;c<2;)
              n+=s[j+r][i+c++]==43;
          if(n&&n<3)*p=43;
        }
      }
    }
    memcpy(s,t,42*42);
    Sleep(200);
  }
}
#include <windows.h>
main(i,r,c,n,j,m){char*p,t[42][42],s[42][42]={0};int*f=fopen("i","r");while(fgets(s[i++]+1,40,f));for(;;){for(j=1;j<41;++j){printf(s[j]+1);for(i=1;i<41;++i){p=&t[j][i];m=*p=s[j][i];if(m==43)*p=45;if(m==45)*p=42;if(m==42){for(r=-1,n=0;r<2;++r)for(c=-1;c<2;)n+=s[j+r][i+c++]==43;if(n&&n<3)*p=43;}}}memcpy(s,t,42*42);Sleep(200);}}

C, 355 347 300 chars

Edit: Saved 47 chars! Removed the Sleep, got rid of almost all braces, combined a lot of operations.

C does not lend itself well to this sort of problem, but hey, golfing it is fun. This is a pretty brute-force implementation, but I wanted to see how far I could golf it up.

char*p,t[42][42],s[42][42];
main(i,r,c,n,j)
{
  for(p=fopen("i","r");fgets(s[i++]+1,40,p););

  for(;;getch(),memcpy(s,t,1764))
    for(j=1;j<41;printf(s[j++]+1))
      for(i=1;i<41;)
      {
        p=t[j]+i;
        r=*p=s[j][i++];
        if(r==43)
          *p=45;
        if(r==45)
          *p=42;
        if(r==42)
          for(r=-1,n=0;r<2;++r,*p=n&&n<3?43:42)
            for(c=-2;c<1;)
              n+=s[j+r][i+c++]==43;
      }
}
char*p,t[42][42],s[42][42];main(i,r,c,n,j){for(p=fopen("i","r");fgets(s[i++]+1,40,p););for(;;getch(),memcpy(s,t,1764))for(j=1;j<41;printf(s[j++]+1))for(i=1;i<41;){p=t[j]+i;r=*p=s[j][i++];if(r==43)*p=45;if(r==45)*p=42;if(r==42)for(r=-1,n=0;r<2;++r,*p=n&&n<3?43:42)for(c=-2;c<1;)n+=s[j+r][i+c++]==43;}}
2 added 20 characters in body
source | link

C, 355355 347 chars

Edit: realized I don't need feof()

C does not lend itself well to this sort of problem, but hey, golfing it is fun. This is a pretty brute-force implementation, but I wanted to see how far I could golf it up. There's also no built-in sleep function in the C libraries, so I had to #include <windows.h> to get Sleep() to slow down the display.

Input is a text file named i. It contains a representation of the starting state, with * for copper, + for electron head, - for electron tail, spaces for empty cells. I'm using the XOR gate from the wiki page for testing.

   ****-+**
  +        ******
   -*******      *
                ****
                *  *****
                ****
   ********      *
  +        ******
   -****+-*

#include <windows.h>

main(i,r,c,n,j,m)
{
  char*p,t[42][42],s[42][42]={0};

  int*f=fopen("i","r");
  while(!feof(f))
    fgets(s[i++]+1,40,f));

  for(;;)
  {
    for(j=1;j<41;++j)
    {
      printf(s[j]+1);
      for(i=1;i<41;++i)
      {
        p=&t[j][i];
        m=*p=s[j][i];
        if(m==43)
          *p=45;
        if(m==45)
          *p=42;
        if(m==42)
        {
          for(r=-1,n=0;r<2;++r)
            for(c=-1;c<2;)
              n+=s[j+r][i+c++]==43;
          if(n&&n<3)*p=43;
        }
      }
    }
    memcpy(s,t,42*42);
    Sleep(200);
  }
}

Whitespace removed:

#include <windows.h>
main(i,r,c,n,j,m){char*p,t[42][42],s[42][42]={0};int*f=fopen("i","r");while(!feof(f))fgets(s[i++]+1,40,f));for(;;){for(j=1;j<41;++j){printf(s[j]+1);for(i=1;i<41;++i){p=&t[j][i];m=*p=s[j][i];if(m==43)*p=45;if(m==45)*p=42;if(m==42){for(r=-1,n=0;r<2;++r)for(c=-1;c<2;)n+=s[j+r][i+c++]==43;if(n&&n<3)*p=43;}}}memcpy(s,t,42*42);Sleep(200);}}

C, 355 chars

C does not lend itself well to this sort of problem, but hey, golfing it is fun. This is a pretty brute-force implementation, but I wanted to see how far I could golf it up. There's also no built-in sleep function in the C libraries, so I had to #include <windows.h> to get Sleep() to slow down the display.

Input is a text file named i. It contains a representation of the starting state, with * for copper, + for electron head, - for electron tail, spaces for empty cells. I'm using the XOR gate from the wiki page for testing.

   ****-+**
  +        ******
   -*******      *
                ****
                *  *****
                ****
   ********      *
  +        ******
   -****+-*

#include <windows.h>

main(i,r,c,n,j,m)
{
  char*p,t[42][42],s[42][42]={0};

  int*f=fopen("i","r");
  while(!feof(f))
    fgets(s[i++]+1,40,f);

  for(;;)
  {
    for(j=1;j<41;++j)
    {
      printf(s[j]+1);
      for(i=1;i<41;++i)
      {
        p=&t[j][i];
        m=*p=s[j][i];
        if(m==43)
          *p=45;
        if(m==45)
          *p=42;
        if(m==42)
        {
          for(r=-1,n=0;r<2;++r)
            for(c=-1;c<2;)
              n+=s[j+r][i+c++]==43;
          if(n&&n<3)*p=43;
        }
      }
    }
    memcpy(s,t,42*42);
    Sleep(200);
  }
}

Whitespace removed:

#include <windows.h>
main(i,r,c,n,j,m){char*p,t[42][42],s[42][42]={0};int*f=fopen("i","r");while(!feof(f))fgets(s[i++]+1,40,f);for(;;){for(j=1;j<41;++j){printf(s[j]+1);for(i=1;i<41;++i){p=&t[j][i];m=*p=s[j][i];if(m==43)*p=45;if(m==45)*p=42;if(m==42){for(r=-1,n=0;r<2;++r)for(c=-1;c<2;)n+=s[j+r][i+c++]==43;if(n&&n<3)*p=43;}}}memcpy(s,t,42*42);Sleep(200);}}

C, 355 347 chars

Edit: realized I don't need feof()

C does not lend itself well to this sort of problem, but hey, golfing it is fun. This is a pretty brute-force implementation, but I wanted to see how far I could golf it up. There's also no built-in sleep function in the C libraries, so I had to #include <windows.h> to get Sleep() to slow down the display.

Input is a text file named i. It contains a representation of the starting state, with * for copper, + for electron head, - for electron tail, spaces for empty cells. I'm using the XOR gate from the wiki page for testing.

   ****-+**
  +        ******
   -*******      *
                ****
                *  *****
                ****
   ********      *
  +        ******
   -****+-*

#include <windows.h>

main(i,r,c,n,j,m)
{
  char*p,t[42][42],s[42][42]={0};

  int*f=fopen("i","r");
  while(fgets(s[i++]+1,40,f));

  for(;;)
  {
    for(j=1;j<41;++j)
    {
      printf(s[j]+1);
      for(i=1;i<41;++i)
      {
        p=&t[j][i];
        m=*p=s[j][i];
        if(m==43)
          *p=45;
        if(m==45)
          *p=42;
        if(m==42)
        {
          for(r=-1,n=0;r<2;++r)
            for(c=-1;c<2;)
              n+=s[j+r][i+c++]==43;
          if(n&&n<3)*p=43;
        }
      }
    }
    memcpy(s,t,42*42);
    Sleep(200);
  }
}

Whitespace removed:

#include <windows.h>
main(i,r,c,n,j,m){char*p,t[42][42],s[42][42]={0};int*f=fopen("i","r");while(fgets(s[i++]+1,40,f));for(;;){for(j=1;j<41;++j){printf(s[j]+1);for(i=1;i<41;++i){p=&t[j][i];m=*p=s[j][i];if(m==43)*p=45;if(m==45)*p=42;if(m==42){for(r=-1,n=0;r<2;++r)for(c=-1;c<2;)n+=s[j+r][i+c++]==43;if(n&&n<3)*p=43;}}}memcpy(s,t,42*42);Sleep(200);}}
1
source | link