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.

251 tokens in C for part 1 by dbasden

Download solution

#include<stdio.h>

chargrid[256][256];
intwidth,height;

typedefstruct{
inti;
intj;
}pos_t;

staticpos_telf_loc;
staticpos_telf_vec={-1,0};

intmain(){
while(scanf("%s%n\n",&(grid[++height][0]),&width)==1)
for(intj=0;j<=width;++j)
if(grid[height][j]=='^')
elf_loc=(pos_t){height,j};
while(grid[elf_loc.i][elf_loc.j]){
grid[elf_loc.i][elf_loc.j]='X';
pos_tforward=(pos_t){elf_loc.i+elf_vec.i,elf_loc.j+elf_vec.j};
if(grid[forward.i][forward.j]!='#')elf_loc=forward;
elseelf_vec=(pos_t){elf_vec.j,-elf_vec.i};
}

intvisited=0;
for(inti=1;i<height;++i)for(intj=0;j<width;++j)visited+=grid[i][j]=='X';
printf("%d\n",visited);
}