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

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