234 tokens in Kotlin for part 1 by Michael Böiers
Download solution
funmain(){
funString.press(t:String)=when{
t[0]=='*'->(toInt()*t.drop(1).toInt()).toString()
t[0]=='/'->(toInt()/t.drop(1).toInt()).toString()
"->"int->replace(t[0],t.last())
t=="oct"->toInt().toString(8)
t=="bksp"->(if(length==1)"0"elsedropLast(1))
this=="0"->t
else->this+t
}.takeUnless{it.length>4}?:this
valtokens=readln().split(" ").map{it.drop(1).dropLast(1)}
varv=setOf("0")
repeat(3){
v=v.flatMap{tokens.map(it::press)}.toSet()
}
println(v.sumOf(String::toInt))
}