Skip to content

Instantly share code, notes, and snippets.

@wesgarrison
Created October 18, 2014 04:05
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 wesgarrison/c15f22a3271eb0152414 to your computer and use it in GitHub Desktop.
Save wesgarrison/c15f22a3271eb0152414 to your computer and use it in GitHub Desktop.
skeletons
Dir.glob('*in.txt').each do |filename|
puts "\n -------- #{filename}"
expected = File.read("#{filename[0]}_out.txt").chomp
result = `ruby solution.rb < #{filename}`.chomp
if result.to_s == expected.to_s
puts " WORKS"
else
puts " FAILS"
result = result.split("\n")
count = 0
expected.split("\n").each_with_index do |expected_line, index|
count = index + 1
puts "#{index.to_s.ljust(3)}#{expected_line.ljust(60)} #{expected_line == result[index].to_s ? '=' : '!'} #{result[index].to_s.rjust(60)}"
end
if result.slice(count, 99999)
result.slice(count , 99999).each {|r| puts "#{' ' * 63} ! #{r.to_s.rjust(60)}" }
end
puts ""
# exit
end
end
# cat 1_in.txt | ruby solution.rb
class Base
def initialize(args)
@arg1, @arg2, @arg3, @arg4 = args.read.split("\n")
p @arg1.split(':').last # label:value
p @arg2.split(':').last
p @arg3.split(':').last.split(',') # label:val1,val2,val3,...
p @arg4 = @arg4.split(':').last.split(',')
end
def go
# use the things here
end
private
end
# Base.new(ARGV).go
Base.new(ARGF).go
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment