You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

main.go 1.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package main
  2. import (
  3. "fmt"
  4. "github.com/csmith/aoc-2019/common"
  5. "github.com/csmith/aoc-2019/intcode"
  6. )
  7. const shipSize = 100
  8. func main() {
  9. input := common.ReadCsvAsInts("19/input.txt")
  10. vm := intcode.NewVirtualMachine(make([]int, len(input)))
  11. var endPositions [shipSize]int
  12. endIndex := 0
  13. sum := 0
  14. lastStart := 0
  15. for y := 0; ; y++ {
  16. first := 0
  17. for x := lastStart; ; x++ {
  18. vm.Reset(input)
  19. if *vm.RunForInput(x, y) == 1 {
  20. if first == 0 {
  21. first = x
  22. }
  23. if x < 50 && y < 50 {
  24. sum++
  25. }
  26. } else if first > 0 || y < 50 && x > 50 {
  27. // For y < 50 if we hit x > 50 without finding the beam, assume it's not there. (The beam isn't
  28. // continuous at the start, there's a couple of blanks).
  29. if x-first >= shipSize-1 {
  30. previousEnd := endPositions[endIndex]
  31. if previousEnd-shipSize >= first-1 {
  32. fmt.Println(sum)
  33. fmt.Println((previousEnd-shipSize)*10000 + (y - 100))
  34. return
  35. }
  36. endPositions[endIndex] = x
  37. endIndex = (endIndex + 1) % shipSize
  38. }
  39. break
  40. }
  41. }
  42. lastStart = first
  43. }
  44. }