Bash: 2022 day 4 part 2
This commit is contained in:
@@ -22,11 +22,9 @@ parse() {
|
||||
|
||||
while IFS=-, read -ra _arr; do
|
||||
# arrange the two sections so that the lowest is the first
|
||||
printf "_arr=%s\n" "${_arr[*]}"
|
||||
if ((_arr[0] > _arr[2])); then
|
||||
((_tmp=_arr[0], _arr[0]=_arr[2], _arr[2]=_tmp))
|
||||
((_tmp=_arr[1], _arr[1]=_arr[3], _arr[3]=_tmp))
|
||||
printf "\t->%s\n" "${_arr[*]}"
|
||||
fi
|
||||
sections+=("${_arr[*]}")
|
||||
done
|
||||
@@ -45,6 +43,17 @@ part1() {
|
||||
done
|
||||
}
|
||||
|
||||
part2() {
|
||||
declare -ig res=0
|
||||
local -a _sect
|
||||
|
||||
for line in "${sections[@]}"; do
|
||||
# shellcheck disable=SC2206
|
||||
_sect=($line)
|
||||
(( _sect[2] <= _sect[1] )) && (( res++ ))
|
||||
done
|
||||
}
|
||||
|
||||
solve() {
|
||||
if (($1 == 1)); then
|
||||
part1
|
||||
|
Reference in New Issue
Block a user