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

2

u/mus1Kk Dec 01 '15

I did

$ perl -E 'for(split//,shift){$x+=/\(/?1:-1};END{say$x}' '()()'

and expanded to

$ perl -E 'for(split//,shift){$i++;$x+=/\(/?1:-1;if($x<0){say$i}};END{say$x}' '()()'

for part 2.

2

u/Aneurysm9 Dec 01 '15

apparently this works for part 1 too

perl -nE 'print tr/(//-tr/)//' input