]> git.sommitrealweird.co.uk Git - advent-of-code-2019.git/commitdiff
Minor refactor start
authorBrett Parker <iDunno@sommitrealweird.co.uk>
Tue, 8 Dec 2020 21:28:45 +0000 (21:28 +0000)
committerBrett Parker <iDunno@sommitrealweird.co.uk>
Tue, 8 Dec 2020 21:29:30 +0000 (21:29 +0000)
day10/check_asteroids.sh
day10/common.sh [new file with mode: 0644]

index bf545445e8b9852429a3a65902836ea59d20e5de..efda3592252571b2e69c873d55c446fa4563cc11 100755 (executable)
@@ -5,6 +5,8 @@ set -e
 
 basedir=$(dirname $(readlink -f ${BASH_SOURCE}))
 
 
 basedir=$(dirname $(readlink -f ${BASH_SOURCE}))
 
+. $basedir/common.sh
+
 filename=${1:-$basedir/3_4_8.txt}
 
 exec 3<$filename
 filename=${1:-$basedir/3_4_8.txt}
 
 exec 3<$filename
@@ -37,18 +39,6 @@ debug_line() {
     echo "$line" >&2
 }
 
     echo "$line" >&2
 }
 
-get_vector() {
-    local x1=$1
-    local y1=$2
-    local x2=$3
-    local y2=$4
-
-    x_diff=$(($x1 - $x2))
-    y_diff=$(($y1 - $y2))
-
-    echo "$x_diff,$y_diff"
-}
-
 check_collision() {
     # we want to know if vector2 is going to get in the way of vector1
     local vector1=$1
 check_collision() {
     # we want to know if vector2 is going to get in the way of vector1
     local vector1=$1
diff --git a/day10/common.sh b/day10/common.sh
new file mode 100644 (file)
index 0000000..86979ed
--- /dev/null
@@ -0,0 +1,25 @@
+get_vector() {
+    local x1=$1
+    local y1=$2
+    local x2=$3
+    local y2=$4
+
+    x_diff=$(($x1 - $x2))
+    y_diff=$(($y1 - $y2))
+
+    echo "$x_diff,$y_diff"
+}
+
+get_asteroids_vector() {
+    local a1=$1
+    local a2=$2
+
+    local x1=${a1%,*}
+    local y1=${a1#*,}
+    local x2=${a2%,*}
+    local y2=${a2%*,}
+
+    get_vector $x1 $y1 $x2 $y2
+}
+
+