logo

adventofcode

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

day2.0 (729B)


  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 (A, X)
  7. # - 2 for Paper (B, Y)
  8. # - 3 for Scissors (C, Z)
  9. # Object(Rock, Paper, Scissors) + 3 if draw or 6 if won, 0 if lost
  10. /X/ { score += 1 }
  11. /Y/ { score += 2 }
  12. /Z/ { score += 3 }
  13. /A X/ { score += 3 } # Rock-Rock
  14. /A Y/ { score += 6 } # Rock-Paper
  15. /A Z/ { score += 0 } # Rock-Scissors
  16. /B X/ { score += 0 } # Paper-Rock
  17. /B Y/ { score += 3 } # Paper-Paper
  18. /B Z/ { score += 6 } # Paper-Scissors
  19. /C X/ { score += 6 } # Scissors-Rock
  20. /C Y/ { score += 0 } # Scissors-Paper
  21. /C Z/ { score += 3 } # Scissors-Scissors
  22. END { print score }