]> git.sommitrealweird.co.uk Git - advent-of-code-2019.git/blob - day11/run2.sh
95205601bee9a69b131f592b23533d007a27ced4
[advent-of-code-2019.git] / day11 / run2.sh
1 #!/bin/bash
2
3 set -u
4 set -e
5
6 exec 3<input.txt
7
8 OLDIFS=$IFS
9 IFS=","
10 read -u 3 -a data
11 IFS=$OLDIFS
12
13 base_dir=$(dirname $(readlink -f $BASH_SOURCE))
14 . computer.sh
15 . robot.sh
16
17 # start the computer as a coproc
18 coproc computer (run_program data)
19
20 while ( kill -0 $computer_PID >/dev/null 2>&1 ); do
21     get_robot_paint_colour >&${computer[1]}
22     read -u ${computer[0]} direction
23     read -u ${computer[0]} colour
24     do_robot_paint_and_move $direction $colour
25     sleep 0.1
26 done
27
28 # just incase the spinner is still about
29 echo -n $'\r'"                "$'\r'
30
31 # we've done all the painting, now lets display it
32 draw_panel
33
34 echo
35 echo "Painted: $(get_robot_paint_count) panels at least once"