diff --git a/day03/main.go b/day03/main.go index 6394ff6..ad2c1f8 100644 --- a/day03/main.go +++ b/day03/main.go @@ -27,7 +27,7 @@ type symbol struct { } type symbolTab map[int]map[int]*symbol -func hasSymbol(tab symbolTab, row, col int, p partNumber) bool { +func (tab symbolTab) hasSymbol(row, col int, p partNumber) bool { if cols, ok := tab[row]; ok { s, ok := cols[col] if ok { @@ -38,14 +38,13 @@ func hasSymbol(tab symbolTab, row, col int, p partNumber) bool { } return false } -func scanSymbol(tab symbolTab, p partNumber) bool { +func (tab symbolTab) scanSymbol(p partNumber) bool { rowStart, rowEnd := max(p.row-1, 0), p.row+1 colStart, colEnd := max(p.col-1, 0), p.end+1 for i := rowStart; i <= rowEnd; i++ { for j := colStart; j <= colEnd; j++ { - ok := hasSymbol(tab, i, j, p) - // fmt.Println(p.number, i, j, ok) + ok := tab.hasSymbol(i, j, p) if ok { return true } @@ -54,19 +53,20 @@ func scanSymbol(tab symbolTab, p partNumber) bool { return false } +// 553079 +// 84363105 + func main() { buf := bytes.NewReader(input) scan := bufio.NewScanner(buf) - m := [][]rune{} parts := []partNumber{} symbols := make(symbolTab) symbolList := []*symbol{} - + row := 0 for scan.Scan() { text := scan.Text() - row := len(m) - m = append(m, []rune(text)) + row += 1 slice := make([]rune, 0, 3) var col int @@ -100,7 +100,7 @@ func main() { sum := 0 for i, p := range parts { - ok := scanSymbol(symbols, p) + ok := symbols.scanSymbol(p) parts[i].hasSymbol = ok if ok { sum += p.number @@ -114,10 +114,9 @@ func main() { } } - fmt.Println(m) - fmt.Println(parts) - fmt.Println(symbols) - fmt.Println(symbolList) - fmt.Println(sum) - fmt.Println(sumGears) + // fmt.Println(parts) + // fmt.Println(symbols) + // fmt.Println(symbolList) + fmt.Println("part1:", sum) + fmt.Println("part2:", sumGears) }