Post History
Scala, 45 bytes _./:(Seq[Int]())((a,x)=>a:+x dropRight-x*2+2) Try it in Scastie! I couldn't find a way to use underscores in the inner function :(. Explanation on its way. _ //The inp...
Answer
#2: Post edited
- # Scala, 45 bytes
- ```scala
- _./:(Seq[Int]())((a,x)=>a:+x dropRight-x*2+2)
- ```
- [Try it in Scastie!](https://scastie.scala-lang.org/aY6dy1O9RrS0VUgiX3O8Rw)
I couldn't find a way to use underscores in the inner function :(. Explanation on its way.
- # Scala, 45 bytes
- ```scala
- _./:(Seq[Int]())((a,x)=>a:+x dropRight-x*2+2)
- ```
- [Try it in Scastie!](https://scastie.scala-lang.org/aY6dy1O9RrS0VUgiX3O8Rw)
- I couldn't find a way to use underscores in the inner function :(. Explanation on its way.
- ```scala
- _ //The input
- ./:( //Fold over it,
- Seq[Int]() //starting with an empty list,
- )( //using this function
- (a,x) => //a is the accumulator, x is the current element
- a:+x //Append x to a
- dropRight //then drop an element from the right if x is 0
- -x*2+2 //For 0, this is 2
- //(drop the 0 that we just appended and the previous element)
- //and for other numbers, it's negative, so it doesn't do anything
- )
- ```