Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@gmhawash
Created December 10, 2013 16:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gmhawash/7893698 to your computer and use it in GitHub Desktop.
Save gmhawash/7893698 to your computer and use it in GitHub Desktop.
pather code.
#!/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