206 tokens in Kotlin for part 1 by Vadzim Kapichenka
Download solution
funmain()=println(
generateSequence(::readLine).sumOf{
val(target,buttons)=it.run{
subSequence(1,indexOf(']')).foldRight(0){c,bits->
bitsshl1orif(c=='#')1else0
}tosubSequence(indexOf('(')+1,lastIndexOf(')')).split(") (").map{
it.splitToSequence(',').fold(0){bits,s->bitsor(1shls.toInt())}
}
}
valvisited=mutableSetOf<Int>()
generateSequence(listOf(0to0)){states->
states.flatMap{(step,state)->
buttons.map{step+1to(itxorstate)}.filter{visited.add(it.second)}
}
}.flatten().dropWhile{it.second!=target}.first().first
}
)