refactor range checks

remove unnecessary print
This commit is contained in:
onyx-and-iris 2023-12-11 19:34:14 +00:00
parent af3e483382
commit 23be028cd3
2 changed files with 6 additions and 22 deletions

View File

@ -37,29 +37,15 @@ func shortestRoute(a, b coords, factor int) int {
vert := int(math.Abs(float64(b.Y - a.Y))) vert := int(math.Abs(float64(b.Y - a.Y)))
for _, row := range empty["row"] { for _, row := range empty["row"] {
if b.Y > a.Y { if row >= a.Y && row < b.Y || row >= b.Y && row < a.Y {
if row >= a.Y && row < b.Y { log.Debug("empty row, adding to vert")
log.Debug("empty row, adding to vert") vert += (factor - 1)
vert += (factor - 1)
}
} else {
if row >= b.Y && row < a.Y {
log.Debug("empty row, adding to vert")
vert += (factor - 1)
}
} }
} }
for _, col := range empty["col"] { for _, col := range empty["col"] {
if b.X > a.X { if col >= a.X && col < b.X || col >= b.X && col < a.X {
if col >= a.X && col < b.X { log.Debug("empty col, adding to horz")
log.Debug("empty col, adding to horz") horz += (factor - 1)
horz += (factor - 1)
}
} else {
if col >= b.X && col < a.X {
log.Debug("empty col, adding to horz")
horz += (factor - 1)
}
} }
} }

View File

@ -2,7 +2,6 @@ package main
import ( import (
"bufio" "bufio"
"fmt"
"log" "log"
"os" "os"
"strings" "strings"
@ -32,7 +31,6 @@ func parseInput(lines []string) {
for j, r := range line { for j, r := range line {
runes[i] = append(runes[i], r) runes[i] = append(runes[i], r)
if r == '#' { if r == '#' {
fmt.Println(x, j, i)
galaxies = append(galaxies, newGalaxy(x, j, i)) galaxies = append(galaxies, newGalaxy(x, j, i))
x++ x++
} }