Skip to content

Instantly share code, notes, and snippets.

@takahashilabo
Created June 17, 2017 22:42
Show Gist options
  • Save takahashilabo/4fa47d98dd6d123b1fdcfd538122e4d8 to your computer and use it in GitHub Desktop.
Save takahashilabo/4fa47d98dd6d123b1fdcfd538122e4d8 to your computer and use it in GitHub Desktop.
This code counts consecutive lines in standard input
data = []
while s = gets
data << s.chomp
end
tmp = {}
data.each do |item|
if tmp.has_key?(item) then
tmp[item] << item
else
tmp[item] = [item]
end
end
tmp.each_key do |key|
print key, ",", tmp[key].size, "\n"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment