fork download
  1. object Main extends App {
  2. val f = (n:Int)=>{val s=n.toString;(for{c<-s if c!='-'}yield(c-48)*(if(s.indexOf(c)==1&&s.charAt(0)=='-') -1 else 1)).sum+n+s.length}
  3. println(f(99))
  4. println(f(-123))
  5. println(f(0))
  6. println(f(-1))
  7. }
Success #stdin #stdout 0.36s 322432KB
stdin
Standard input is empty
stdout
119
-115
1
0