Golfcoder FAQ LOGIN
Error

Advent of Code Leaderboard 2024 / Day 6

View puzzle on adventofcode.com

Submit solution



Leaderboard

Name Language Tokens Sum Tokens Part 1 Tokens Part 2 Last change
1 Profile imageCornerMercury Python 269 102 167 42 days ago
2 Profile imagedbasden C 561 251 310 42 days ago
3 Profile imageSzabolcs Dombi Python 10141 141 - 42 days ago
4 Profile imageMechazawa JavaScript 10206 206 - 38 days ago
5 Profile imageTomáš Mach Python 10234 234 - 42 days ago

Rules

  • You're welcome to participate alone or in a team.
  • You may submit multiple solutions and explore different programming languages.
  • Stick to the standard library of your language, no further dependencies/libraries, except the ones which OneCompiler provides (e.g. NumPy for Python).
  • Ensure your code aligns to the template (Python, Rust, Go, Kotlin, JavaScript, C#, TypeScript, C++, Java, C, Swift, Scala, Ruby, Bash), reading the puzzle input from stdin (terminated with end-of-file), and printing the solution to stdout.
  • Please refrain from making network requests, reading data from files, or storing data in variable/function/class names for reflection.
  • Your code must be able to process all valid Advent of Code inputs. Golfcoder might reevaluate correctness of your solution with different inputs after your submission.

310 tokens in C for part 2 by dbasden

Download solution

#include<stdio.h>

typedefstruct{
inti;
intj;
}pos_t;

#defineELFOFF






[elf_pos.i][elf_pos.j]
#definegijgrid[i][j]
chargrid[256][256];
intwidth,part_2_result,i,j;
pos_telf_start_pos,oob;

intevi[4]={-1,0,1},evj[4]={0,1,0,-1};

intdoes_guard_loop(){
intvec_idx=0;
intvisited[256][256][4]={};
pos_telf_pos=elf_start_pos;

while(gridELFOFF){
if(visitedELFOFF[vec_idx])return1;
visitedELFOFF[vec_idx]=1;
pos_tforward=(pos_t){elf_pos.i+evi[vec_idx],elf_pos.j+evj[vec_idx]};
if(grid[forward.i][forward.j]!=35&&!(forward.i==i&&forward.j==j))
elf_pos=forward;
elsevec_idx=(vec_idx+1)&3;
}
return0;
}

intmain(){
while(scanf("%s%n",&(grid[++i][0]),&width)==1)
for(j=0;j<width;++j)
if(gij==94)elf_start_pos=(pos_t){i,j};
for(i=1;i<width;++i)
for(j=0;j<width;++j)
part_2_result+=gij!=94&&does_guard_loop();
printf("%d\n",part_2_result);
}