From 23be028cd32d8a5b9dbaac40be21704fd7c31d36 Mon Sep 17 00:00:00 2001 From: onyx-and-iris Date: Mon, 11 Dec 2023 19:34:14 +0000 Subject: [PATCH] refactor range checks remove unnecessary print --- day-11/one.go | 26 ++++++-------------------- day-11/util.go | 2 -- 2 files changed, 6 insertions(+), 22 deletions(-) diff --git a/day-11/one.go b/day-11/one.go index a2a73d4..0e315ec 100644 --- a/day-11/one.go +++ b/day-11/one.go @@ -37,29 +37,15 @@ 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 { - 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) - } + if row >= a.Y && row < b.Y || 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 { - 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) - } + if col >= a.X && col < b.X || col >= b.X && col < a.X { + log.Debug("empty col, adding to horz") + horz += (factor - 1) } } diff --git a/day-11/util.go b/day-11/util.go index f165157..cea9953 100644 --- a/day-11/util.go +++ b/day-11/util.go @@ -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++ }