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()}}
)
}