]> git.sommitrealweird.co.uk Git - advent-of-code-2020.git/blob - day02/get_valid_count_2.sh
Day 14 - implemented in bash, because, well, I could
[advent-of-code-2020.git] / day02 / get_valid_count_2.sh
1 #!/bin/bash
2
3 check_file() {
4     cat input.txt | while read line; do
5         password=${line#*: }
6         params=${line%: *}
7         min=${params%-*}
8         params=${params#*-}
9         max=${params% *}
10         char=${params#* }
11         count=0
12         min=$((min-1))
13         max=$((max-1))
14         if [ "${password:$min:1}" = "$char" ] || [ "${password:$max:1}" = "$char" ]; then
15             if [ "${password:$min:1}" != "${password:$max:1}" ]; then
16                 echo "Got valid line! $line"
17             fi
18         fi
19     done
20 }
21
22 echo "Got $(check_file | wc -l) valid lines"
23
24 exit 0