162 tokens in Kotlin for part 2 by Fabian Schedler
Download solution
funmain()=println(
generateSequence(::readLine).toList().run{
valrowsToExpand=indices.filter{y->'#'!inthis[y]}
valcolumnsToExpand=indices.filter{x->none{it[x]=='#'}}
flatMapIndexed{y,row->
row.mapIndexedNotNull{x,value->
if(value!='#')nullelsey+rowsToExpand.count{it<y}*999_999Ltox+columnsToExpand.count{it<x}*999_999L
}
}.run{flatMap{map(it::to)}}
.sumOf{it.run{Math.abs(first.first-second.first)+Math.abs(first.second-second.second)}}/2
}
)