mirror of
https://github.com/onyx-and-iris/aoc2023.git
synced 2024-11-24 19:30:48 +00:00
refactor range checks
remove unnecessary print
This commit is contained in:
parent
af3e483382
commit
23be028cd3
@ -37,30 +37,16 @@ func shortestRoute(a, b coords, factor int) int {
|
||||
vert := int(math.Abs(float64(b.Y - a.Y)))
|
||||
|
||||
for _, row := range empty["row"] {
|
||||
if b.Y > a.Y {
|
||||
if row >= a.Y && row < b.Y {
|
||||
if row >= a.Y && row < b.Y || row >= b.Y && row < a.Y {
|
||||
log.Debug("empty row, adding to vert")
|
||||
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"] {
|
||||
if b.X > a.X {
|
||||
if col >= a.X && col < b.X {
|
||||
if col >= a.X && col < b.X || col >= b.X && col < a.X {
|
||||
log.Debug("empty col, adding to horz")
|
||||
horz += (factor - 1)
|
||||
}
|
||||
} else {
|
||||
if col >= b.X && col < a.X {
|
||||
log.Debug("empty col, adding to horz")
|
||||
horz += (factor - 1)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return int(math.Abs(float64(horz + vert)))
|
||||
|
@ -2,7 +2,6 @@ package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"strings"
|
||||
@ -32,7 +31,6 @@ func parseInput(lines []string) {
|
||||
for j, r := range line {
|
||||
runes[i] = append(runes[i], r)
|
||||
if r == '#' {
|
||||
fmt.Println(x, j, i)
|
||||
galaxies = append(galaxies, newGalaxy(x, j, i))
|
||||
x++
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user