Created
January 2, 2015 00:06
-
-
Save mawaldne/34d7dd9977b9fbe65473 to your computer and use it in GitHub Desktop.
[2014-12-28] Challenge #195 [Easy] Symbolic Link Resolution
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
# run as: ruby sym_link_reso.rb input.txt | |
lines = open(ARGV[0]).readlines | |
directory = lines.last | |
symlinks = lines[1..-2].each_with_object({}) do |line, hash| | |
symlink = line.chomp.split(':') | |
hash[symlink[0].chomp("/")] = symlink[1].chomp("/") | |
end | |
while symlinks.keys.any? { |symlink| directory.include?(symlink) } do | |
symlinks.each do |key, value| | |
directory.gsub!(key, value) | |
end | |
end | |
puts directory | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment