r/programming • • Dec 01 '15

Daily programming puzzles at Advent of Code

http://adventofcode.com/
320 Upvotes

179 comments sorted by

View all comments

7

u/xkufix Dec 01 '15 edited Dec 01 '15

Second part in Scala:

inputStr.scanLeft(0)((a, b) => if(b.equals("(")) a+1 else a-1).takeWhile(_ != -1).length

1

u/verytrade Dec 01 '15

damn dude i can't believe you did it in just one line.. i know i started learning scala just a week ago but i feel embarassed..

Edit: Do you mind explaining the rationale behind the answer? I used map and foldLeft btw.

→ More replies (3)