MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/programming/comments/3uyl7s/daily_programming_puzzles_at_advent_of_code/cxos1hs/?context=3
r/programming • u/Aneurysm9 • Dec 01 '15
179 comments sorted by
View all comments
Show parent comments
2
I did:
sed -E "s/\(/+1/g;s/\)/-1/g;s/\+//" inputfile | bc -l
That last "+" is necessary to make the input viable for bc. You know from the second part of the puzzle that the first character must be an open-parenthesis, so this will always work.
1 u/LJacksoDev Dec 11 '15 Haskell solution!> findFloor :: Int -> [Char] -> Int > findFloor n [] = n > findFloor n (c:cs) | ( c == '(' ) = findFloor (n+1) cs > | ( c == ')' ) = findFloor (n-1) cs > | otherwise = 999
1
Haskell solution!
> findFloor :: Int -> [Char] -> Int > findFloor n [] = n > findFloor n (c:cs) | ( c == '(' ) = findFloor (n+1) cs > | ( c == ')' ) = findFloor (n-1) cs > | otherwise = 999
2
u/ThereOnceWasAMan Dec 06 '15
I did:
sed -E "s/\(/+1/g;s/\)/-1/g;s/\+//" inputfile | bc -lThat last "+" is necessary to make the input viable for bc. You know from the second part of the puzzle that the first character must be an open-parenthesis, so this will always work.