X-Git-Url: https://git.sommitrealweird.co.uk/advent-of-code-2019.git/blobdiff_plain/8d19ec771c083ce8bbfff9b075d42f15ad704831..24a0a2360eb2e4b4332ce45ba5888e72f970428a:/day7/part2.sh?ds=sidebyside diff --git a/day7/part2.sh b/day7/part2.sh deleted file mode 100644 index 5f3c705..0000000 --- a/day7/part2.sh +++ /dev/null @@ -1,82 +0,0 @@ -#!/bin/bash - -set -u -set -e - -. "$(dirname $(readlink -f "$BASH_SOURCE"))/computer.sh" - -exec 3&${amps_stdin[$a]} - read -u ${amps_stdout[$a]} output - a=$((a+1)) - done - - # that's all the amps started up, now we loop until amp1 stops, then we stop feeding amp5's - # data to it and read that's last output instead - while ( ps -p $amp1_PID >/dev/null 2>&1 ); do - for (( a=1; a<=5; a++ )); do - echo $output >&${amps_stdin[$a]} - read -u ${amps_stdout[$a]} output - done - done - - echo "$output" -} - -values="56789" -biggest_output=0 -biggest_order="01234" -for (( a=0; a<${#values}; a++ )); do - values_2="${values:0:$a}${values:$((a+1))}" - value_1=${values:$a:1} - for (( b=0; b<${#values_2}; b++ )); do - values_3="${values_2:0:$b}${values_2:$((b+1))}" - value_2=${values_2:$b:1} - for (( c=0; c<${#values_3}; c++ )); do - values_4="${values_3:0:$c}${values_3:$((c+1))}" - value_3=${values_3:$c:1} - for (( d=0; d<${#values_4}; d++ )); do - value_5="${values_4:0:$d}${values_4:$((d+1))}" - value_4="${values_4:d:1}" - output="$(run_amplifier $value_1 $value_2 $value_3 $value_4 $value_5 2>/dev/null)" - if [ $output -gt $biggest_output ]; then - biggest_output=$output - biggest_order="${value_1}${value_2}${value_3}${value_4}${value_5}" - fi - done - done - done -done - -echo "Got biggest output $biggest_output with phases $biggest_order" - -exit 0 - -output=0 -for val in 4 3 2 1 0; do - output=$(echo -e "$val\n$output" | run_program orig_data) -done -echo $output -