#!/bin/bash read line target=( $(sed 's/^.*x=\(.*\)\.\.\(.*\), y=\(.*\)\.\.\(.*\)/\1 \2 \3 \4/' <<< $line) ) possible_x=() for ((i=1;i<=target[1];i++)); do velocity_x=$i position_x=0 while [ $velocity_x -gt 0 ] && [ $position_x -lt ${target[0]} ]; do position_x=$((position_x+velocity_x)) velocity_x=$((velocity_x-1)) done if [ $position_x -ge ${target[0]} ] && [ $position_x -le ${target[1]} ]; then possible_x+=( $i ) fi done highest_y=0 declare -A possible_velocities for ((i=0;i<${#possible_x[@]};i++)); do possible_y=$((target[2]*(-1)-1)) for ((j=$possible_y;j>=${target[2]};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_x -ge ${target[0]} ] && [ $position_y -ge ${target[2]} ] \ && [ $position_x -le ${target[1]} ] && [ $position_y -le ${target[3]} ]; then possible_velocities[${possible_x[$i]},$j]=1 break fi done done done echo ${#possible_velocities[@]}