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