Skip to content

Instantly share code, notes, and snippets.

@schnell18
Created June 5, 2020 13:02
Show Gist options
  • Save schnell18/219bec5ebc4efb4bc07a1a2e33511dd2 to your computer and use it in GitHub Desktop.
Save schnell18/219bec5ebc4efb4bc07a1a2e33511dd2 to your computer and use it in GitHub Desktop.
Max temperature reducer in Ruby
#!/usr/bin/env ruby
last_key, max_val = nil, -1000000
STDIN.each_line do |line|
key, val = line.split("\t")
if last_key && last_key != key
puts "#{last_key}\t#{max_val}"
last_key, max_val = key, val.to_i
else
last_key, max_val = key, [max_val, val.to_i].max
end
end
puts "#{last_key}\t#{max_val}" if last_key
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment