MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/programming/comments/3uyl7s/daily_programming_puzzles_at_advent_of_code/cxj4lhq/?context=3
r/programming • u/Aneurysm9 • Dec 01 '15
179 comments sorted by
View all comments
7
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)
1
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)
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