您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

main.go 523B

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