#!/bin/bash

check=0
cur_number=0
prev_number=0
count=0
cur_line=0
cur_window=1

declare -a windows

filename="${1:-input.txt}"

for num in $(<"$filename"); do
    cur_line=$((cur_line+1))
    windows[$cur_window]=$num
    if [ $cur_window -gt 1 ]; then
        ((windows[$((cur_window - 1))]+=$num))
    fi
    if [ $cur_window -gt 2 ]; then
        ((windows[$((cur_window - 2))]+=$num))
    fi
    ((cur_window+=1))

    case $check in
        0)
            check=1
            cur_number=$num
            prev_number=$num
            continue
            ;;
        1)
            cur_number=$num
            if [ $cur_number -gt $prev_number ]; then
                ((count+=1))
            fi
            prev_number=$num
            ;;
    esac
done

# remove last 2 entries for windows array
unset windows[$((cur_window+1))]
unset windows[$((cur_window+2))]

echo "$count is the answer"

# start from window 2, then we just compare to previous
window=2
count=0

while [ $window -le ${#windows[@]} ]; do
    if [ ${windows[$((window-1))]} -lt ${windows[$window]} ]; then
        ((count+=1))
    fi
    ((window+=1))
done

echo "$count is the 3 value sum answer"
