Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <#
- "The first column is what your opponent is going to play: A for Rock, B for Paper, and C for Scissors. The second column--"
- X for Rock, Y for Paper, and Z for Scissors
- total score is the sum of your scores for each round
- score for a single round is the score for the shape you selected (1 for Rock, 2 for Paper, and 3 for Scissors),
- plus the score for the outcome of the round (0 if you lost, 3 if the round was a draw, and 6 if you won)
- #>
- $gameRounds = $puzzelInput -split '\n' | Select -SkipLast 1
- Function Invoke-PaperRockScissors {
- Param ([string[]]$gameRounds)
- Process {
- $didIlose = @{
- 'A Z' = $true
- 'B X' = $true
- 'C Y' = $true
- }
- $translateMove = @{
- 'X' = 'A'
- 'Y' = 'B'
- 'Z' = 'C'
- }
- $shapeScore = @{
- 'X' = 1
- 'Y' = 2
- 'Z' = 3
- }
- $roundScores = foreach ($row in $gameRounds) {
- $opponentMove,$playerMove = $null
- $opponentMove,$playerMove = $row -split ' '
- # Did I lose?
- If ($didIlose["$row"] -eq $true) {
- $shapeScore["$playerMove"]
- continue
- }
- # Did I tie?
- If ($opponentMove -eq $translateMove["$playerMove"]) {
- $shapeScore["$playerMove"] + 3
- continue
- }
- $shapeScore["$playerMove"] + 6
- }
- ($roundScores | Measure-Object -Sum).Sum
- }
- }
- Invoke-PaperRockScissors $gameRounds
- # Part 2
- # X means you need to lose, Y means you need to end the round in a draw, and Z means you need to win
- $translateStrategy = @{
- 'AL' = 'A Z'
- 'AD' = 'A X'
- 'AW' = 'A Y'
- 'BL' = 'B X'
- 'BD' = 'B Y'
- 'BW' = 'B Z'
- 'CL' = 'C Y'
- 'CD' = 'C Z'
- 'CW' = 'C X'
- }
- $newPuzzelInput = foreach ($row in $gameRounds) {
- $opponentMove,$playerMove = $null
- $opponentMove,$playerMove = $row -split ' '
- switch ($playerMove) {
- 'X' {$translateStrategy["$($opponentMove)L"]} # lose
- 'Y' {$translateStrategy["$($opponentMove)D"]} # draw
- 'Z' {$translateStrategy["$($opponentMove)W"]} #
- }
- }
- Invoke-PaperRockScissors $newPuzzelInput
Advertisement
Add Comment
Please, Sign In to add comment