I'm reproducing the second part of the first day of Advent of Code, with permission from the creator.
Santa is trying to deliver presents in a large apartment building, but he can't find the right floor - the directions he got are a little confusing. He starts on the ground floor (floor 0) and then follows the instructions one character at a time.
An opening parenthesis, (
, means he should go up one floor, and a closing parenthesis, )
, means he should go down one floor.
The apartment building is very tall, and the basement is very deep; he will never find the top or bottom floors.
Given a set of instructions, find the position of the first character that causes him to enter the basement (floor -1).
As examples:
input )
causes him to enter the basement at character position 1.
input ()())
causes him to enter the basement at character position 5.
A long input is given here that should yield the solution 1797.
This is code golf, so the shortest solution wins!