2022 Day 15, part 1 complete
Going home from C&C
This commit is contained in:
@@ -13,17 +13,55 @@ var sleepTime = (time.Second / 5)
|
||||
|
||||
var minx, miny, maxx, maxy int
|
||||
|
||||
var part = -1
|
||||
var knots = 2
|
||||
|
||||
func main() {
|
||||
inp := h.StdinToStringSlice()
|
||||
|
||||
watch := len(os.Args) > 1 && strings.HasPrefix(os.Args[1], "-w")
|
||||
if watch {
|
||||
if strings.Contains(os.Args[1], "=") {
|
||||
pts := strings.Split(os.Args[1], "=")
|
||||
sleepTime = (time.Second / time.Duration(h.Atoi(pts[1])))
|
||||
var watch bool
|
||||
var partSet bool
|
||||
if len(os.Args) > 1 {
|
||||
for _, arg := range os.Args[1:] {
|
||||
if strings.HasPrefix(arg, "-w") {
|
||||
watch = true
|
||||
if strings.Contains(arg, "=") {
|
||||
pts := strings.Split(arg, "=")
|
||||
sleepTime = (time.Second / time.Duration(h.Atoi(pts[1])))
|
||||
}
|
||||
} else if strings.HasPrefix(arg, "-k") {
|
||||
if strings.Contains(arg, "=") {
|
||||
pts := strings.Split(arg, "=")
|
||||
knots = h.Atoi(pts[1])
|
||||
}
|
||||
} else if strings.HasPrefix(arg, "-p") {
|
||||
partSet = true
|
||||
if strings.Contains(arg, "=") {
|
||||
pts := strings.Split(arg, "=")
|
||||
part = h.Atoi(pts[1])
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
simulate(inp, 10, watch)
|
||||
if part == 1 {
|
||||
knots = 2
|
||||
} else if part == 2 {
|
||||
knots = 10
|
||||
}
|
||||
if !watch && !partSet {
|
||||
// Run both parts
|
||||
fmt.Println("# Part 1")
|
||||
simulate(inp, 2, watch)
|
||||
fmt.Println()
|
||||
fmt.Println("# Part 2")
|
||||
simulate(inp, 10, watch)
|
||||
} else {
|
||||
if part > 0 && part <= 2 {
|
||||
fmt.Println("# Part", part)
|
||||
} else {
|
||||
fmt.Println("# Simulation with", knots, "knots")
|
||||
}
|
||||
simulate(inp, knots, watch)
|
||||
}
|
||||
}
|
||||
|
||||
func buildInstructions(inp []string) []byte {
|
||||
@@ -48,7 +86,6 @@ func simulate(inp []string, knotCount int, watch bool) {
|
||||
knots = append(knots, h.Coordinate{X: 0, Y: 0})
|
||||
}
|
||||
if watch {
|
||||
fmt.Println("# Part 1")
|
||||
printVisits(visited, knots)
|
||||
}
|
||||
for i, dir := range inst {
|
||||
@@ -57,7 +94,7 @@ func simulate(inp []string, knotCount int, watch bool) {
|
||||
if watch {
|
||||
time.Sleep(sleepTime)
|
||||
fmt.Print(h.CLEAR_SCREEN)
|
||||
fmt.Printf("# Part 1 (%d/%d)\n", i, len(inst))
|
||||
fmt.Printf("# Knots %d (%d/%d)\n", knots, i, len(inst))
|
||||
printVisits(visited, knots)
|
||||
}
|
||||
}
|
||||
@@ -65,7 +102,6 @@ func simulate(inp []string, knotCount int, watch bool) {
|
||||
time.Sleep(sleepTime)
|
||||
fmt.Print(h.CLEAR_SCREEN)
|
||||
}
|
||||
fmt.Println("# Part 1")
|
||||
if watch {
|
||||
printVisits(visited, knots)
|
||||
}
|
||||
|
Reference in New Issue
Block a user