Created
December 3, 2016 05:44
-
-
Save evantravers/ee72562e1807cdd67e576f3a86dc5443 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# google advent of code solution #1 | |
input = File.read "instructions.txt" | |
instructions = input.split ', ' | |
# first is left, second is right | |
directions = { | |
:north => [:west, :east], | |
:east => [:north, :south], | |
:south => [:east, :west], | |
:west => [:south, :north], | |
} | |
current_coord = { :x => 0, :y => 0 } | |
facing_direction = :north | |
instructions.each do |instruction| | |
direction = instruction[0] | |
distance = instruction[1..-1].to_i | |
if direction == "L" | |
new_facing_direction = directions[facing_direction].first | |
else | |
new_facing_direction = directions[facing_direction].last | |
end | |
puts "#{new_facing_direction} for #{distance} blocks" | |
facing_direction = new_facing_direction | |
if facing_direction == :north | |
current_coord[:y] += distance | |
elsif facing_direction == :east | |
current_coord[:x] += distance | |
elsif facing_direction == :south | |
current_coord[:y] -= distance | |
elsif facing_direction == :west | |
current_coord[:x] -= distance | |
end | |
end | |
puts current_coord |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
L4, R2, R4, L5, L3, L1, R4, R5, R1, R3, L3, L2, L2, R5, R1, L1, L2, R2, R2, L5, R5, R5, L2, R1, R2, L2, L4, L1, R5, R2, R1, R1, L2, L3, R2, L5, L186, L5, L3, R3, L5, R4, R2, L5, R1, R4, L1, L3, R3, R1, L1, R4, R2, L1, L4, R5, L1, R50, L4, R3, R78, R4, R2, L4, R3, L4, R4, L1, R5, L4, R1, L2, R3, L2, R5, R5, L4, L1, L2, R185, L5, R2, R1, L3, R4, L5, R2, R4, L3, R4, L2, L5, R1, R2, L2, L1, L2, R2, L2, R1, L5, L3, L4, L3, L4, L2, L5, L5, R2, L3, L4, R4, R4, R5, L4, L2, R4, L5, R3, R1, L1, R3, L2, R2, R1, R5, L4, R5, L3, R2, R3, R1, R4, L4, R1, R3, L5, L1, L3, R2, R1, R4, L4, R3, L3, R3, R2, L3, L3, R4, L2, R4, L3, L4, R5, R1, L1, R5, R3, R1, R3, R4, L1, R4, R3, R1, L5, L5, L4, R4, R3, L2, R1, R5, L3, R4, R5, L4, L5, R2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment