Day 8: Resonant Collinearity

Megathread guidelines

  • Keep top level comments as only solutions, if you want to say something other than a solution put it in a new post. (replies to comments can be whatever)
  • You can send code in code blocks by using three backticks, the code, and then three backticks or use something such as https://topaz.github.io/paste/ if you prefer sending it through a URL

FAQ

  • sjmulder ( sjmulder@lemmy.sdf.org ) 
    link
    fedilink
    English
    arrow-up
    1
    ·
    2 years ago

    C

    Not hard but a little fiddly.

    Code
    #include "common.h"
    
    #define GZ 52
    
    static char g[GZ][GZ];
    #define ANTI_P1 1
    #define ANTI_P2 2
    static uint8_t anti[GZ][GZ];
    static int w,h;
    
    int
    main(int argc, char **argv)
    {
    	int p1=0,p2=0, x,y, x1,y1, ax,ay, i;
    	char *lf;
    
    	if (argc > 1)
    		DISCARD(freopen(argv[1], "r", stdin));
    	for (h=0; hw ||
    				    (ay = y-(y1-y)*i) <0 || ay>h)
    					break;
    				anti[ay][ax] |= ANTI_P1 * i==1;
    				anti[ay][ax] |= ANTI_P2;
    			}
    
    			for (i=0; ; i++) {
    				if ((ax = x1+(x1-x)*i) <0 || ax>w ||
    				    (ay = y1+(y1-y)*i) <0 || ay>h)
    					break;
    				anti[ay][ax] |= ANTI_P1 * i==1;
    				anti[ay][ax] |= ANTI_P2;
    			}
    		}
    	}
    
    	for (y=0; y