#!/bin/bash read line target=( $(sed 's/^.*x=\(.*\)\.\.\(.*\), y=\(.*\)\.\.\(.*\)/\1 \2 \3 \4/' <<< $line) ) possible_x=() for ((i=1;i0;j--)); do velocity_x=${possible_x[$i]} velocity_y=$j position_x=0 position_y=0 while [ $position_x -le ${target[1]} ] && [ $position_y -ge ${target[2]} ]; do position_x=$((position_x+velocity_x)) position_y=$((position_y+velocity_y)) velocity_x=$((velocity_x-1)) if [ $velocity_x -lt 0 ]; then velocity_x=0 fi velocity_y=$((velocity_y-1)) if [ $position_y -gt $temp_highest_y ]; then temp_highest_y=$position_y fi if [ $position_x -ge ${target[0]} ] && [ $position_y -ge ${target[2]} ] \ && [ $position_x -le ${target[1]} ] && [ $position_y -le ${target[3]} ]; then if [ $temp_highest_y -gt $highest_y ]; then highest_y=$temp_highest_y fi break fi done done done echo $highest_y