r/programming • • Dec 01 '15

Daily programming puzzles at Advent of Code

http://adventofcode.com/
320 Upvotes

179 comments sorted by

View all comments

Show parent comment

1

u/knipil Dec 01 '15

Another functional approach for the second one (in beautiful O(n2) time):

c = [x == "(" and 1 or -1 for x in list(str)]
[x for x in xrange(1, len(c)+1) if sum(c[0:x]) == -1][0]