Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #https://adventofcode.com/2021/day/2
- # WebRequest to gather your puzzle input
- $cookie_id = "53616xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
- $session = New-Object Microsoft.PowerShell.Commands.WebRequestSession
- $session.Cookies.Add((New-Object System.Net.Cookie("session", $cookie_id, "/", ".adventofcode.com")))
- $moves = Invoke-WebRequest -UseBasicParsing -Uri "https://adventofcode.com/2021/day/2/input" ` -WebSession $session
- $moves = $moves.Content
- [int]$horizontal = [int]$depth = 0
- # Format the input content as an array by splitting it line by line
- $moves = $moves -split("\n")
- $moves | % {
- # Split each row in 2 parts : command and value
- $move = $_.split(" ")
- # Depending on the command, increase or decrease required values
- switch($move[0]){
- "down"{
- $depth += [int]$move[1]
- }
- "up"{
- $depth -= [int]$move[1]
- }
- "forward"{
- $horizontal+= [int]$move[1]
- }
- }
- }
- $final_result = $depth*$horizontal
Add Comment
Please, Sign In to add comment