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

123456789101112131415161718192021222324252627282930
  1. package main
  2. import (
  3. "fmt"
  4. "github.com/csmith/aoc-2019/common"
  5. )
  6. func main() {
  7. input := common.ReadFileAsStrings("22/input.txt")
  8. deckSize := 10007
  9. position := 2019
  10. for _, line := range input {
  11. var n int
  12. if "deal into new stack" == line {
  13. position = deckSize - 1 - position
  14. } else if _, err := fmt.Sscanf(line, "cut %d", &n); err == nil {
  15. n = (n + deckSize) % deckSize
  16. if position < n {
  17. position += deckSize - n
  18. } else {
  19. position -= n
  20. }
  21. } else if _, err := fmt.Sscanf(line, "deal with increment %d", &n); err == nil {
  22. position = (position * n) % deckSize
  23. } else {
  24. panic(fmt.Sprintf("Unrecognised line: %s", line))
  25. }
  26. }
  27. println(position)
  28. }