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

12345678910111213141516171819202122232425262728293031323334
  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, true)
  22. vm.Input <- 1
  23. go vm.Run()
  24. fmt.Println(last(vm.Output))
  25. vm.Reset(input)
  26. vm.Input <- 5
  27. go vm.Run()
  28. fmt.Println(last(vm.Output))
  29. }