35 lines
887 B
Bash
35 lines
887 B
Bash
source 2-1.sh
|
|
|
|
tolerant_is_gradual_monotone () {
|
|
# Echoes 1 if the arguments are gradual monotone or if removing
|
|
# a single argument will make the rest gradual monotone. 0 otherwise.
|
|
|
|
local output=0
|
|
if [ $(is_gradual_monotone $@) -eq 1 ]; then
|
|
output=1
|
|
else
|
|
local i=1
|
|
while [ $i -le $# ]; do
|
|
subarray=$( echo $@ | cut -d ' ' -f $i --complement )
|
|
if [ $(is_gradual_monotone $subarray) -eq 1 ]; then
|
|
output=1
|
|
break
|
|
fi
|
|
i=$((i + 1))
|
|
done
|
|
fi
|
|
echo $output
|
|
}
|
|
|
|
main_2_2 () {
|
|
num_gradual_monotone=0
|
|
|
|
while read line; do
|
|
line_is_gradual_monotone=$(tolerant_is_gradual_monotone $line)
|
|
num_gradual_monotone=$((num_gradual_monotone + line_is_gradual_monotone))
|
|
done <<< $(cat input.txt)
|
|
|
|
echo $num_gradual_monotone
|
|
}
|
|
|
|
# main_2_2 |