Skip to content

Instantly share code, notes, and snippets.

@tkojitu
Created May 7, 2012 03:55
Show Gist options
  • Save tkojitu/2625807 to your computer and use it in GitHub Desktop.
Save tkojitu/2625807 to your computer and use it in GitHub Desktop.
okwave.jp/qa/q7454381.html
class MyRecord
def initialize(line)
@alpha, @number, @value = line.split
end
attr_reader :alpha, :number, :value
end
def print_alpha_number(records)
num_keys = records.map{|rec| rec.number}.uniq.sort
alpha_keys = records.map{|rec| rec.alpha}.uniq.sort
$stdout.puts(" " + alpha_keys.join(" "))
num_keys.each do |nkey|
$stdout.print(nkey)
alpha_keys.each do |akey|
$stdout.printf(" %s", find_by_number_alpha(records, nkey, akey).value)
end
$stdout.puts
end
end
def find_by_number_alpha(records, number, alpha)
return records.find{|rec| rec.number == number && rec.alpha == alpha}
end
$records = []
ARGF.readlines.each{|line| $records << MyRecord.new(line)}
print_alpha_number($records)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment