tidy up
This commit is contained in:
+7
-6
@@ -2,13 +2,14 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"sort"
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
const bitSize = 40
|
const bitSize = 12
|
||||||
|
|
||||||
func bitComplement(num uint64) uint64 {
|
func bitComplement(num uint64) uint64 {
|
||||||
return ^num & (1<<bitSize - 1)
|
return ^num & (1<<bitSize - 1)
|
||||||
@@ -56,7 +57,7 @@ func partTwo(s []string) (int64, int64) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func solve() {
|
func solve() {
|
||||||
file, err := os.Open("bigboi.txt")
|
file, err := os.Open("input.txt")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
@@ -81,10 +82,10 @@ func solve() {
|
|||||||
total++
|
total++
|
||||||
}
|
}
|
||||||
|
|
||||||
partOne(&counts, &total)
|
gamma, epsilon := partOne(&counts, &total)
|
||||||
//fmt.Println(int64(g) * int64(e))
|
fmt.Println(int64(gamma) * int64(epsilon))
|
||||||
partTwo(s)
|
o2, co2 := partTwo(s)
|
||||||
//fmt.Println(o * c)
|
fmt.Println(o2 * co2)
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|||||||
+21
-9
@@ -28,13 +28,12 @@ func createLine(s []string) *Line {
|
|||||||
return l
|
return l
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *Line) Walk() []Point {
|
func (l *Line) Walk() (p []Point, isDiagonal bool) {
|
||||||
var p []Point
|
|
||||||
|
|
||||||
xstart, xend := minMax(l.start.x, l.end.x)
|
xstart, xend := minMax(l.start.x, l.end.x)
|
||||||
ystart, yend := minMax(l.start.y, l.end.y)
|
ystart, yend := minMax(l.start.y, l.end.y)
|
||||||
// diagonal line
|
// diagonal line
|
||||||
if xend-xstart == yend-ystart {
|
if xend-xstart == yend-ystart {
|
||||||
|
isDiagonal = true
|
||||||
for x, y := l.start.x, l.start.y; ; {
|
for x, y := l.start.x, l.start.y; ; {
|
||||||
p = append(p, Point{x: x, y: y})
|
p = append(p, Point{x: x, y: y})
|
||||||
if x == l.end.x {
|
if x == l.end.x {
|
||||||
@@ -62,7 +61,7 @@ func (l *Line) Walk() []Point {
|
|||||||
p = append(p, Point{x: l.start.x, y: y})
|
p = append(p, Point{x: l.start.x, y: y})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return p
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func minMax(a int, b int) (min int, max int) {
|
func minMax(a int, b int) (min int, max int) {
|
||||||
@@ -87,23 +86,36 @@ func main() {
|
|||||||
r := regexp.MustCompile("[0-9]+")
|
r := regexp.MustCompile("[0-9]+")
|
||||||
|
|
||||||
floorMap := make(map[Point]int)
|
floorMap := make(map[Point]int)
|
||||||
|
var overlapCount int
|
||||||
|
diags := make([]Point, 0)
|
||||||
|
|
||||||
for scanner.Scan() {
|
for scanner.Scan() {
|
||||||
text := scanner.Text()
|
text := scanner.Text()
|
||||||
coords := r.FindAllString(text, -1)
|
coords := r.FindAllString(text, -1)
|
||||||
line := createLine(coords)
|
line := createLine(coords)
|
||||||
points := line.Walk()
|
points, isDiagonal := line.Walk()
|
||||||
|
|
||||||
|
if isDiagonal {
|
||||||
|
diags = append(diags, points...)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
for _, p := range points {
|
for _, p := range points {
|
||||||
|
if floorMap[p] == 1 {
|
||||||
|
overlapCount++
|
||||||
|
}
|
||||||
floorMap[p]++
|
floorMap[p]++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var overlapCount int
|
fmt.Println("Part one: ", overlapCount)
|
||||||
for _, v := range floorMap {
|
|
||||||
if v > 1 {
|
for _, p := range diags {
|
||||||
|
if floorMap[p] == 1 {
|
||||||
overlapCount++
|
overlapCount++
|
||||||
}
|
}
|
||||||
|
floorMap[p]++
|
||||||
}
|
}
|
||||||
fmt.Println(overlapCount)
|
|
||||||
|
fmt.Println("Part two: ", overlapCount)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user