Golfcoder FAQ LOGIN
Error

Advent of Code Leaderboard 2024 / Day 12

View puzzle on adventofcode.com

Submit solution



Leaderboard

Name Language Tokens Sum Tokens Part 1 Tokens Part 2 Last change
1 Profile imageMichael Böiers Kotlin 10215 215 - 8 days ago
2 Profile imagedbasden C 10344 344 - 9 days ago
3 Profile imageMechazawa Rust 11183 1183 - 8 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.

215 tokens in Kotlin for part 1 by Michael Böiers

Download solution

typealiasPlot=Pair<Int,Int>

funmain(){
valgrid=generateSequence(::readLine).flatMapIndexed{y,l->l.mapIndexed{x,c->xtoytoc}}.toMap()

funPlot.neighbors()=
sequenceOf(first-1tosecond,first+1tosecond,firsttosecond-1,firsttosecond+1)
.filter{grid[it]==grid[this]}

println(
grid
.keys
.fold(mutableSetOf<Pair<Char,Set<Plot>>>()){acc,plot->
if(acc.none{plotinit.second})
acc+=grid[plot]!!tobuildSet{
add(plot)
while(true)flatMap(Plot::neighbors).filterNot(::contains).takeIf{it.isNotEmpty()}
?.also(::addAll)
?:break
}
acc
}.sumOf{it.second.size*it.second.sumOf{4-it.neighbors().count()}}
)
}