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 636B

12345678910111213141516171819202122232425262728293031323334353637
  1. package main
  2. import (
  3. "github.com/csmith/aoc-2019/common"
  4. "github.com/csmith/aoc-2019/intcode"
  5. )
  6. func last(channel <-chan int) (res int) {
  7. for {
  8. o, more := <-channel
  9. if more {
  10. res = o
  11. } else {
  12. return
  13. }
  14. }
  15. }
  16. func main() {
  17. input := common.ReadCsvAsInts("09/input.txt")
  18. memory := make([]int, len(input))
  19. copy(memory, input)
  20. vm := intcode.NewVirtualMachine(memory)
  21. vm.Input = make(chan int, 1)
  22. vm.Output = make(chan int, 1)
  23. vm.Input <- 1
  24. go vm.Run()
  25. println(last(vm.Output))
  26. vm.Reset(input)
  27. vm.Input = make(chan int, 1)
  28. vm.Output = make(chan int, 1)
  29. vm.Input <- 2
  30. go vm.Run()
  31. println(last(vm.Output))
  32. }