projects
/
advent-of-code-2020.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Fix small breakages in bash versions
[advent-of-code-2020.git]
/
day4
/
count_valid_passports_2.sh
diff --git
a/day4/count_valid_passports_2.sh
b/day4/count_valid_passports_2.sh
index 6eb2b08e46e5e5530f42beb0576e0bec33b8be63..88fc560b0e0c54ed2b7f3fdfe7b3357f18ca4d74 100644
(file)
--- a/
day4/count_valid_passports_2.sh
+++ b/
day4/count_valid_passports_2.sh
@@
-128,6
+128,17
@@
while read -u 3 line; do
seperator=" "
done
seperator=" "
done
+check_fields() {
+ local -n record=$1
+ for field in ${required_fields[@]}; do
+ if ! [ ${record[$field]+a} ]; then
+ exit 1
+ fi
+ done
+
+ exit 0
+}
+
# on the last line, if cur_data isn't empty, add that to the array
if [ "$cur_data" != "" ]; then
data+=("$cur_data")
# on the last line, if cur_data isn't empty, add that to the array
if [ "$cur_data" != "" ]; then
data+=("$cur_data")
@@
-141,13
+152,10
@@
for (( i=0; i<${#data[@]}; i++ )); do
value=${field#*:}
kvp[$key]=$value
done
value=${field#*:}
kvp[$key]=$value
done
- for field in ${required_fields[@]}; do
- if
! [ ${kvp[$field]+a} ]
; then
- continue 2
+ if ( check_fields kvp ); then
+ if
( check_data kvp )
; then
+ valid_count=$((valid_count+1))
fi
fi
- done
- if ( check_data kvp ); then
- valid_count=$((valid_count+1))
fi
unset kvp
done
fi
unset kvp
done