logo

adventofcode

Code used to solve https://adventofcode.com/, one branch per year git clone https://hacktivis.me/git/adventofcode.git

day2.1 (649B)


  1. #!/bin/awk -f
  2. # SPDX-FileCopyrightText: 2022 Haelwenn (lanodan) Monnier <contact+adventofcode@hacktivis.me>
  3. # SPDX-License-Identifier: BSD-3-Clause
  4. # (ABC) → Opponent
  5. # (XYZ) → You
  6. # +1 for Rock
  7. # +2 for Paper
  8. # +3 for Scissors
  9. BEGIN {
  10. rock = 1
  11. paper = 2
  12. scissors = 3
  13. loose = 0 # X
  14. draw = 3 # Y
  15. win = 6 # Z
  16. }
  17. # Rock
  18. /A X/ { score += loose+scissors }
  19. /A Y/ { score += draw+rock }
  20. /A Z/ { score += win+paper }
  21. # Paper
  22. /B X/ { score += loose+rock }
  23. /B Y/ { score += draw+paper }
  24. /B Z/ { score += win+scissors }
  25. # Scissors
  26. /C X/ { score += loose+paper }
  27. /C Y/ { score += draw+scissors }
  28. /C Z/ { score += win+rock }
  29. END { print score }