MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/programming/comments/3uyl7s/daily_programming_puzzles_at_advent_of_code/cxjjk61/?context=3
r/programming • u/Aneurysm9 • Dec 01 '15
179 comments sorted by
View all comments
Show parent comment
1
I did the same! except
xclip -o | sed 's/(/1+/g;s/)/-1+/g;s/+$/\n/' | bc
I could probably have made it shorter and dropped the \n at the end if I had copied a newline in the clipboard..
\n
edit: Part 2:
#!/usr/bin/bash declare floor=0 step=0 declare -a instructions mapfile -t instructions < <(grep -o .) while [[ $floor != -1 ]]; do if [[ ${instructions[$step]} == '(' ]]; then (( floor++ )) else (( floor-- )) fi (( step++ )) done echo $step
edit 2: formatting, also I probably should've done this without the external call to grep, and used read -n1..
read -n1
View all comments
Show parent comment
1
u/DanielFGray Dec 01 '15 edited Dec 01 '15
I did the same! except
xclip -o | sed 's/(/1+/g;s/)/-1+/g;s/+$/\n/' | bcI could probably have made it shorter and dropped the
\nat the end if I had copied a newline in the clipboard..edit: Part 2:
edit 2: formatting, also I probably should've done this without the external call to grep, and used
read -n1..