mirror of
https://github.com/onyx-and-iris/aoc2023.git
synced 2024-11-22 02:10:48 +00:00
refactor range checks
remove unnecessary print
This commit is contained in:
parent
af3e483382
commit
23be028cd3
@ -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)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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++
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user