Advertisement
pier4r

aoc 2022 day 2 terraform

Dec 5th, 2022
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | Source Code | 0 0
  1. locals {
  2. process_output_max = true
  3.  
  4. input_rows = split(
  5. "\n",
  6. local.process_output_max ?
  7. data.local_file.input_max.content :
  8. data.local_file.input_mini.content
  9. )
  10.  
  11. # rock 1
  12. # paper 2
  13. # scissors 3
  14. facts_part1 = {
  15. # wins
  16. "A Y" = (2+6)
  17. "B Z" = (3+6)
  18. "C X" = (1+6)
  19. # draws
  20. "A X" = (1+3)
  21. "B Y" = (2+3)
  22. "C Z" = (3+3)
  23. # losses
  24. "A Z" = (3+0)
  25. "B X" = (1+0)
  26. "C Y" = (2+0)
  27. }
  28.  
  29. array_of_scores_p1 = [
  30. # identifies the score given the facts
  31. for pos, value in local.input_rows :
  32. local.facts_part1[value] if value != ""
  33. ]
  34.  
  35. # rock 1
  36. # paper 2
  37. # scissors 3
  38. facts_part2 = {
  39. # wins
  40. "A Z" = (2+6)
  41. "B Z" = (3+6)
  42. "C Z" = (1+6)
  43. # draws
  44. "A Y" = (1+3)
  45. "B Y" = (2+3)
  46. "C Y" = (3+3)
  47. # losses
  48. "A X" = (3+0)
  49. "B X" = (1+0)
  50. "C X" = (2+0)
  51. }
  52.  
  53. array_of_scores_p2 = [
  54. # identifies the score given the facts
  55. for pos, value in local.input_rows : #range(0, length(local.input_rows)) is not usable for lists larger of 1024, and it is worse than index and value.
  56. local.facts_part2[value] if value != ""
  57. ]
  58. }
  59.  
  60. # Read the contents of a text file into a Terraform variable
  61. data "local_file" "input_mini" {
  62. filename = "/Users/pier_work_settings/local/scripting/recreational_math_and_prog/puppet/aoc_2022_2_input_mini.txt"
  63. }
  64.  
  65. data "local_file" "input_max" {
  66. filename = "/Users/pier_work_settings/local/scripting/recreational_math_and_prog/puppet/aoc_2022_2_input_max.txt"
  67. }
  68.  
  69. output "part1" {
  70. value = sum(local.array_of_scores_p1)
  71. }
  72.  
  73. output "part2" {
  74. value = sum(local.array_of_scores_p2)
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement