Created
December 10, 2013 16:39
-
-
Save gmhawash/7893698 to your computer and use it in GitHub Desktop.
pather code.
This file contains hidden or 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
#!/usr/bin/env ruby | |
class Pather | |
def initialize(input) | |
@input = input.split("\n") | |
end | |
def output | |
x1 = nil | |
@input.each do |line| | |
unless x1 | |
x1 = (line =~ /#/) | |
else | |
line[x1] = '*' if x1 | |
# seek bottom point | |
if x2 = (line =~ /#/) | |
if x1 < x2 | |
first, second = x1, x2 - 1 | |
else | |
first, second = x2 + 1, x1 | |
end | |
line[first..second] = '*' * (second - first + 1).abs | |
break | |
end | |
end | |
end | |
@input | |
end | |
end | |
p "Must provide input file" if ARGV.empty? | |
input_file = ARGV[0] | |
output_file = ARGV[1] || 'output.txt' | |
input = File.open(File.join(File.dirname(__FILE__), input_file)).read | |
pather = Pather.new(input) | |
File.open(File.join(File.dirname(__FILE__), output_file), 'w') {|f| f.puts pather.output.join("\n") } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment