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=0j<=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=1i<height++i)for(intj=0j<width++j)visited+=grid[i][j]=='X'
printf("%d\n",visited)
}