SaltyPeaches

Advent of Code: Day 1 (Part 1)

Dec 2nd, 2016
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $directions = [IO.File]::ReadAllText("D:\scripts\Day1\Sequences.txt") -split ", "
  2.  
  3. $orientation = 0
  4. $x = 0
  5. $y = 0
  6.  
  7. foreach($m in $directions){
  8.     if($m.substring(0,1) -eq 'L'){
  9.         if($orientation -eq 0){
  10.             $orientation = 3
  11.         }
  12.         else{
  13.             $orientation -= 1
  14.         }
  15.     }
  16.     else{
  17.         if($orientation -eq 3){
  18.             $orientation = 0
  19.         }
  20.         else{
  21.             $orientation += 1
  22.         }
  23.     }
  24.  
  25.     if($orientation -eq 0){
  26.         $y += $m.substring(1)
  27.     }
  28.     elseif($orientation -eq 1){
  29.         $x += $m.substring(1)
  30.     }
  31.     elseif($orientation -eq 2){
  32.         $y -= $m.substring(1)
  33.     }
  34.     else{
  35.         $x -= $m.substring(1)
  36.     }
  37.    
  38. }
  39.  
  40. write-host "Bunny HQ is at ($x,$y)"
  41. if($x -lt 0){$x*=-1}
  42. if($y -lt 0){$y*=-1}
  43. write-host "Distance to Bunny HQ:" ($x+$y)
Advertisement
Add Comment
Please, Sign In to add comment