From: Brett Parker Date: Sun, 6 Dec 2020 17:23:35 +0000 (+0000) Subject: First attempt X-Git-Url: https://git.sommitrealweird.co.uk/advent-of-code-2019.git/commitdiff_plain/c4d07ccc686ba834151431d1fbd3cf35fe2f3b06 First attempt --- diff --git a/day3/wires.sh b/day3/wires.sh new file mode 100644 index 0000000..a28765a --- /dev/null +++ b/day3/wires.sh @@ -0,0 +1,235 @@ +#!/bin/bash + +set -u +set -e + +# these wires should give 6 +#wire_1=(R8 U5 L5 D3) +#wire_2=(U7 R6 D4 L4) + +# these wires should get 159 +#wire_1=(R75 D30 R83 U83 L12 D49 R71 U7 L72) +#wire_2=(U62 R66 U55 R34 D71 R55 D58 R83) + +# these wires should get 135 +wire_1=(R98 U47 R26 D63 R33 U87 L62 D20 R33 U53 R51) +wire_2=(U98 R91 D20 R16 D67 R40 U7 R15 U6 R7) + +# read in data from file instead +#exec 3=${min_max[2]}; a-- )); do + echo ${board[$a]} +done + +echo "Wires cross at:" +min_distance=-1 +for cross in "${cross_wires[@]}"; do + echo " $cross" + horz=${cross%,*} + horz=${horz//-/} + vert=${cross#*,} + vert=${vert//-/} + distance=$((horz+$vert)) + if [ $min_distance -lt 0 ] || [ $min_distance -gt $distance ]; then + min_distance=$distance + fi +done + +echo Min distance: $min_distance