Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

main.go 1.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. lastWidth := 0
  16. for y := 0; ; y++ {
  17. first := 0
  18. for x := lastStart; ; x++ {
  19. vm.Reset(input)
  20. if *vm.RunForInput(x, y) == 1 {
  21. if first == 0 {
  22. first = x
  23. if y > 50 {
  24. x += lastWidth
  25. }
  26. }
  27. if x < 50 && y < 50 {
  28. sum++
  29. }
  30. } else if first > 0 || y < 50 && x > 50 {
  31. // For y < 50 if we hit x > 50 without finding the beam, assume it's not there. (The beam isn't
  32. // continuous at the start, there's a couple of blanks).
  33. if x-first >= shipSize-1 {
  34. previousEnd := endPositions[endIndex]
  35. if previousEnd-shipSize >= first-1 {
  36. fmt.Println(sum)
  37. fmt.Println((previousEnd-shipSize)*10000 + (y - 100))
  38. return
  39. }
  40. endPositions[endIndex] = x
  41. endIndex = (endIndex + 1) % shipSize
  42. }
  43. lastWidth = x - first - 1
  44. break
  45. }
  46. }
  47. lastStart = first
  48. }
  49. }