Day 13: Point of Incidence

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)
  • Code block support is not fully rolled out yet but likely will be in the middle of the event. Try to share solutions as both code blocks and using something such as https://topaz.github.io/paste/ , pastebin, or github (code blocks to future proof it for when 0.19 comes out and since code blocks currently function in some apps and some instances as well if they are running a 0.19 beta)

FAQ


🔒 Thread is locked until there’s at least 100 2 star entries on the global leaderboard

🔓 Unlocked

  • sjmulder@lemmy.sdf.org
    link
    fedilink
    arrow-up
    2
    ·
    1 year ago

    C

    Implementing part 1 with a bunch of for loops made me wonder about elegant NumPy solutions but then part 2 came along and it was a perfect fit! Just change a flag to a counter and remove the if-match-early-exit.

    https://github.com/sjmulder/aoc/blob/master/2023/c/day13.c

    int main()
    {
    	static char g[32][32];
    	int p1=0,p2=0, w,h, x,y,i, nmis;
    	
    	while (!feof(stdin)) {
    		for (h=0; ; h++) {
    			assert(h < (int)LEN(*g));
    			if (!fgets(g[h], LEN(*g), stdin)) break;
    			if (!g[h][0] || g[h][0]=='\n') break;
    		}
    
    		assert(h>0); w = strlen(g[0])-1;
    		assert(w>0);
    
    		for (x=1; x