238 tokens in Kotlin for part 2 by Vadzim Kapichenka
Download solution
funmain()=println(
generateSequence(::readLine)
.map{it.split(",").map(String::toLong).run{Triple(get(0),get(1),get(2))}}.toList().run{
asSequence().flatMapIndexed{i,a->drop(i+1).map{atoit}}
.sortedBy{(a,b)->Triple(a.first-b.first,a.second-b.second,a.third-b.third).run{first*first+second*second+third*third}}
.runningFold(get(0)toget(0)towithIndex().associate{it.valuetoit.index}){(_,circuits),(a,b)->
atobtocircuits+circuits.filterValues{it==circuits[b]}.mapValues{circuits[a]!!}
}.dropWhile{it.second.values.toSet().size>1}.first().first.run{first.first*second.first}
}
)