Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- locals {
- process_output_max = true
- input_rows = split(
- "\n",
- local.process_output_max ?
- data.local_file.input_max.content :
- data.local_file.input_mini.content
- )
- # rock 1
- # paper 2
- # scissors 3
- facts_part1 = {
- # wins
- "A Y" = (2+6)
- "B Z" = (3+6)
- "C X" = (1+6)
- # draws
- "A X" = (1+3)
- "B Y" = (2+3)
- "C Z" = (3+3)
- # losses
- "A Z" = (3+0)
- "B X" = (1+0)
- "C Y" = (2+0)
- }
- array_of_scores_p1 = [
- # identifies the score given the facts
- for pos, value in local.input_rows :
- local.facts_part1[value] if value != ""
- ]
- # rock 1
- # paper 2
- # scissors 3
- facts_part2 = {
- # wins
- "A Z" = (2+6)
- "B Z" = (3+6)
- "C Z" = (1+6)
- # draws
- "A Y" = (1+3)
- "B Y" = (2+3)
- "C Y" = (3+3)
- # losses
- "A X" = (3+0)
- "B X" = (1+0)
- "C X" = (2+0)
- }
- array_of_scores_p2 = [
- # identifies the score given the facts
- 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.
- local.facts_part2[value] if value != ""
- ]
- }
- # Read the contents of a text file into a Terraform variable
- data "local_file" "input_mini" {
- filename = "/Users/pier_work_settings/local/scripting/recreational_math_and_prog/puppet/aoc_2022_2_input_mini.txt"
- }
- data "local_file" "input_max" {
- filename = "/Users/pier_work_settings/local/scripting/recreational_math_and_prog/puppet/aoc_2022_2_input_max.txt"
- }
- output "part1" {
- value = sum(local.array_of_scores_p1)
- }
- output "part2" {
- value = sum(local.array_of_scores_p2)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement