Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $directions = [IO.File]::ReadAllText("D:\scripts\Day1\Sequences.txt") -split ", "
- $orientation = 0
- $x = 0
- $y = 0
- foreach($m in $directions){
- if($m.substring(0,1) -eq 'L'){
- if($orientation -eq 0){
- $orientation = 3
- }
- else{
- $orientation -= 1
- }
- }
- else{
- if($orientation -eq 3){
- $orientation = 0
- }
- else{
- $orientation += 1
- }
- }
- if($orientation -eq 0){
- $y += $m.substring(1)
- }
- elseif($orientation -eq 1){
- $x += $m.substring(1)
- }
- elseif($orientation -eq 2){
- $y -= $m.substring(1)
- }
- else{
- $x -= $m.substring(1)
- }
- }
- write-host "Bunny HQ is at ($x,$y)"
- if($x -lt 0){$x*=-1}
- if($y -lt 0){$y*=-1}
- write-host "Distance to Bunny HQ:" ($x+$y)
Advertisement
Add Comment
Please, Sign In to add comment